-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: cannot join current thread #613
Comments
@david30907d 你好 import tqdm
from pathlib import Path
for index, file_path in enumerate(tqdm.tqdm(Path('./').iterdir())):
# let's do something
print(index,file_path) And, if so, does it always raise an error? or occasionally? |
@chengs my fault I didn't finish iterating the loop but break it in the middle when i removed the break clause, nothing error messages pop up. so tqdm doesn't support my code: import tqdm
from pathlib import Path
for index, file_path in enumerate(tqdm.tqdm(Path('./').iterdir())):
if index == num:
break
do_something() |
@david30907d |
@chengs OK, thanks for your fast response |
vis #548 |
I can confirm that break causes this error. It is not present in tqdm versions 4.24.0 and earlier. |
Another example which does not use break and also results in a "cannot join current thread" error: modify the https://github.com/tqdm/tqdm#redirecting-writing example to use a nested progress bar, i.e. replace
by
As of tqdm 4.28.1/Py3.7, this reliably raises the exception after the third outer iteration. |
@anntzer thank you for the feedback. Let me have a look. |
@anntzer can you let me know your environment? (Linux/windows) |
Linux (fedora), miniconda-installed python but packages installed by pip. |
@anntzer I cannot reproduce the error. It will be quite helpful if you can instruct me. from time import sleep
import contextlib
import sys
import tqdm
print(tqdm.__version__)
from tqdm import tqdm
class DummyTqdmFile(object):
"""Dummy file-like that will write to tqdm"""
file = None
def __init__(self, file):
self.file = file
def write(self, x):
# Avoid print() second call (useless \n)
if len(x.rstrip()) > 0:
tqdm.write(x, file=self.file)
def flush(self):
return getattr(self.file, "flush", lambda: None)()
@contextlib.contextmanager
def std_out_err_redirect_tqdm():
orig_out_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
yield orig_out_err[0]
# Relay exceptions
except Exception as exc:
raise exc
# Always restore sys.stdout/err if necessary
finally:
sys.stdout, sys.stderr = orig_out_err
def some_fun(i):
print("Fee, fi, fo,".split()[i])
# Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
with std_out_err_redirect_tqdm() as orig_stdout:
# tqdm needs the original stdout
# and dynamic_ncols=True to autodetect console width
for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
for j in tqdm(range(1), file=orig_stdout, dynamic_ncols=True):
sleep(.1)
some_fun(i)
# After the `with`, printing is restored
print("Done!") |
Ow, wait. I had changed the outer loop to go all the way to
so the RuntimeError occurs while trying to cleanup after an exception thrown from within the loop. Some important points:
|
Looks like #641 fixes the issue for me, thanks for the quick fix. |
I have a similar issue. I don't know exactly what the reason is but - there is no for stm_filepath, sph_filepath in tqdm.tqdm(filepath_pairs, desc='Converting %s data' % mode):
_convert_sample(stm_filepath, sph_filepath, out_dir) where def _convert_sample(stm_file, sph_file, output_dir):
# ...
with open(stm_file) as transcript_file, open(txt_file, 'w') as txt:
jobs = list()
for line_idx, transcript_line in enumerate(transcript_file):
# ...
jobs.append((sph_file, wav_file, start, str(float(end) - float(start))))
pool = Pool(processes=cpu_count())
pool.starmap(_slice_sph_and_convert_to_wav, jobs)
pool.close()
pool.join() The error I see is
Environment
|
@stefan-falk let us wait for the merge of PR #641. The bug will be fixed. |
Hi all, I just ran into this bug as well with two nested tqdm loops keeping track of the progress of a multithreaded python machine learning library. Is there a timetable for this fix? It's a bit of a show-stopper. My program works fine when it's just one tqdm loop. It's only when I have two that everything breaks. Thanks! |
using an earlier version of tqdm seems to solve the issue -- the issue may be related to this issue: tqdm/tqdm#613
tqdm 4.29.0 finally fixed a bug which caused the converters to crash (tqdm/tqdm#613).
I meet this bug too. |
I'm getting the same error when using "set_description" and placing a "break" right after.. |
might really need to fix using #610 or similar |
This is the cmd to install : pip install tqdm==4.24.0 |
this should be already fixed in the current version long time ago. |
read the known issues
environment, where applicable:
version info:
My code:
Error messages:
The text was updated successfully, but these errors were encountered: