This question pertains to Python 3.6.
I have a piece of code which has a thread from the threading library running, as well as the program's main thread. Both threads access an object that is not threadsafe, so I have them locking on a Condition
object before using the object. The thread I spawned only needs to access/update that object once every 5 minutes, so there's a 5 minute sleep timer in the loop.
Currently, the main thread never gets a hold of the lock. When the second thread releases the Condition
and starts waiting on the sleep()
call, the main thread never wakes up/acquires the lock. It's as if the main thread has died.
class Loader:
def __init__(self, q):
...
self.queryLock = threading.Condition()
...
thread = Thread(target=self.threadfunc, daemon=True)
thread.start()
...
self.run()
def threadfunc(self):
...
while True:
self.queryLock.acquire()
[critical section #1]
self.queryLock.notify()
self.queryLock.release()
sleep(300)
def run(self):
...
while True:
...
self.queryLock.acquire()
[critical section #2]
self.queryLock.notify()
self.queryLock.release()
...