multi_progress
multi_progress copied to clipboard
Synchronization issues in threads
First of all thank you for the ideas and code. I was looking for exactly such solution.
However your code has big flaw which might not that obvious and is difficult to encounter on slower machines. The output can get messed when multiple threads are writing to the terminal at same time. What you lack is synchronization between the threads using locking mechanism. Following code change solves this issue:
from multiprocessing import Pool, Lock
...
lock = Lock()
...
def write(self, string):
lock.acquire()
try:
with term.hidden_cursor(): # this is optional
with term.location(*self.location):
print(string)
finally:
lock.release()
...