Skip to content
Create a gist now

Instantly share code, notes, and snippets.

import threading
class WorkerThread(threading.Thread):
def __init__(self, *args, **kwargs):
super(WorkerThread, self).__init__(*args, **kwargs)
self.lock = threading.Lock()
def run(self):
while not self.lock.acquire(False):
# .. do some important stuff
pass
self.lock.release()
def main():
t = WorkerThread()
t.lock.acquire(True)
t.start()
# .. do other important stuff
t.lock.release()
t.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.