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
[Jupyter Lab] visual output bug in nested for loops #1023
Comments
@hongshaoyang Does #433 and #479 are definitely still problematic (despite their "closed" status), but refer to a different bug. |
Solution adapted from here. The most inner loop should be defined outside and updated, refreshed, reset, and closed manually within the loop. If you want the bars to be in sequential order you will have to define them accordingly. This is an example of 1 nested loop (2 loops in total): from tqdm.notebook import tqdm
from time import sleep
iterable_1 = range(10)
iterable_2 = range(100)
pb_1 = tqdm(iterable_1, leave=True)
pb_2 = tqdm(iterable_2, leave=True)
for i in pb_1:
for j in iterable_2:
sleep(0.01) # Do something
pb_2.update() # Update step
pb_2.refresh() # Force display
# Reset 2nd progress bar if it is not the last iteration of outer loop
if i != len(iterable_1)-1: pb_2.reset(total=len(iterable_2))
pb_2.close() Screen.Recording.2022-06-13.at.00.00.19.movFor the progress bars to show up ok in the notebook you need to have nodejs and ipywidgets installed, and try to refresh the web browser. |
Interesting hack, @Claudio9701 . I wonder what the developers think of it. |
import sys
from importlib.metadata import version
print("Python:", sys.version) # conda env with py3.9
print("tqdm:", version("tqdm"))
print("jupyterlab:", version("jupyterlab"))
print("ipywidgets:", version("ipywidgets"))
print("comm:", version("comm"))
# Python: 3.9.15 (main, Nov 4 2022, 16:13:54)
# [GCC 11.2.0]
# tqdm: 4.64.1
# jupyterlab: 3.6.1
# ipywidgets: 8.0.2 # also with jupyterlab==3.5.0 and ipywidgets==7.7.3
# comm: 0.1.0 I have similar problem with this code:
import time
from tqdm.notebook import tqdm
def use_tqdm():
for j in tqdm(range(20)):
for i in tqdm(range(20), leave=False):
time.sleep(0.1)
print("Done") in notebook: from testtqdm import use_tqdm
use_tqdm() Output after finish first nested loop:
Problem is with nested |
Ok, in my case is solved by upgrading the module |
read the known issues
environment, where applicable
Environment
conda list
output:Visual output
The text was updated successfully, but these errors were encountered: