lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
class Thread(QRunnable):
def __init__(self):
super(Thread, self).__init__()
self.mutex = QMutex()
def run(self):
self.mutex.lock()
lst.pop(0)
print(str(lst))
time.sleep(5)
self.mutex.unlock()
The code above is an example of what I am trying to acheive, I have a list that is defined outside the class. I want to periodically pop the first element of the list. If I am running 5 threads I only want one thread to mutate the list at single time. Everytime I try this the 5 threads all try to pop the first element and dont wait as I want. When I recreate this in the native python threading library, it works as intended. What am I doing wrong here?