-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
p0-bug-critical ☢Exception rasingException rasingquestion/docs ‽Documentation clarification candidateDocumentation clarification candidatesynchronisation ⇶Multi-thread/processingMulti-thread/processing
Milestone
Description
tqdm.write()
appears to have a race condition that triggers occasionally:
from tqdm import tqdm
def do_something(_):
tqdm.write('test')
with ThreadPoolExecutor(max_workers=10) as pool:
list(tqdm(pool.map(do_something, range(1000)))
This fixes it:
with ThreadPoolExecutor(max_workers=10) as pool:
progress = tqdm(pool.map(do_something, range(1000))
progress.get_lock()
list(progress)
The issue appears to be in get_lock
:
@classmethod
def get_lock(cls):
"""Get the global lock. Construct it if it does not exist."""
if not hasattr(cls, '_lock'):
cls._lock = TqdmDefaultWriteLock()
return cls._lock
If two threads call this at the same time then the cls._lock
will be overwritten, and cls._lock.release()
at the end of external_write_mode
will release the wrong lock.
Metadata
Metadata
Assignees
Labels
p0-bug-critical ☢Exception rasingException rasingquestion/docs ‽Documentation clarification candidateDocumentation clarification candidatesynchronisation ⇶Multi-thread/processingMulti-thread/processing