Skip to content
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

[tqdm.rich] latest rich breaks the example #1306

Open
andrzejnovak opened this issue Mar 8, 2022 · 22 comments
Open

[tqdm.rich] latest rich breaks the example #1306

andrzejnovak opened this issue Mar 8, 2022 · 22 comments
Labels
p2-bug-warning ⚠ Visual output bad submodule ⊂ Periphery/subclasses

Comments

@andrzejnovak
Copy link

The example doesn't finish after updating rich

image

rich == 11.2.0
tqdm ==  4.63.0
@casperdcl casperdcl added submodule ⊂ Periphery/subclasses p2-bug-warning ⚠ Visual output bad labels Mar 26, 2022
@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

I've also encountered that the progress bar doesn't reach all items. and the outcome is not even constant. i re-run same code and it finishes different positions.

and, the example in file header doesn't even reach beyond 0. this is at least constantly the same.

  • tqdm/tqdm/rich.py

    Lines 4 to 8 in 6791e8c

    Usage:
    >>> from tqdm.rich import trange, tqdm
    >>> for i in trange(10):
    ... ...
    """
➜ cat test-tqdm.py

from tqdm.rich import trange, tqdm
for i in trange(10):
    print(f"i={i}")
print("finished")

➜ python test-tqdm.py
i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7
i=8
i=9
   0% ━━━━━━━━━━━━━━━━━━━━━━━━ 0/10  [ 0:00:00 < -:--:-- , ? it/s ]
finished
➜ pip list|grep -E 'rich|tqdm'
rich               12.6.0
tqdm               4.64.1

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

interesting is that i updated my test to also include sleep(0.1) and now the progressbar increases!.

so the rich progressbar somehow related how often it is updated, so it omits refresh if walked too fast. i guess and lacks final repaint?

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

@andrzejnovak do you have info in what rich version it worked?

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

I think this is a duplicate of the same problem:

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

I've downgraded rich as down as rich==9.6.0,

I could not downgrade more as that's the version Progress.TimeElapsedColumn was first added:

and the problem is still there.

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

I've also downgraded tqdm down as tqdm==4.56.0

I could not downgrade more as that's the version tqdm.rich was added:

so, the issue title is incorrect, this has never worked propertly, not just "latest" version.

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

seems to me that def display() is not called by tqdm if the sleep is removed

  • tqdm/tqdm/rich.py

    Lines 128 to 131 in 6791e8c

    def display(self, *_, **__):
    if not hasattr(self, '_prog'):
    return
    self._prog.update(self._task_id, completed=self.n, description=self.desc)

I added print("display") into the method, and it's not printed at all if the "loop goes to fast".

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

so added trace printing to each display call when progressbar was working:

    def display(self, *_, **__):
        raise "trace"
Traceback (most recent call last):
  File "test-tqdm.py", line 5, in <module>
    for i in it:
  File "python-3.10.8/lib/python3.10/site-packages/tqdm/std.py", line 1175, in __iter__
    self.update(n - last_print_n)
  File "python-3.10.8/lib/python3.10/site-packages/tqdm/std.py", line 1225, in update
    self.refresh(lock_args=self.lock_args)
  File "python-3.10.8/lib/python3.10/site-packages/tqdm/std.py", line 1326, in refresh
    self.display()
  File "python-3.10.8/lib/python3.10/site-packages/tqdm/rich.py", line 134, in display
    raise "trace"

and looking at update() code, the display() call is omitted if it progress goes too fast. and there's calls to display() in std.close, but not in rich.close:

@glensc
Copy link
Contributor

glensc commented Nov 21, 2022

This fixed problem for me:

@kkovary
Copy link

kkovary commented Aug 25, 2023

@glensc that change fixed the problem for me too. Would be great to get #1395 merged 🤞

@glensc
Copy link
Contributor

glensc commented May 3, 2024

#1395 merged, this can be closed

@ma-sadeghi
Copy link

@glensc I still have this problem, although in VS Code interactive Window. I'd appreciate it if you could try it out on VS Code:

import time
from tqdm.rich import trange, tqdm
for i in trange(10):
    time.sleep(0.2)

@glensc
Copy link
Contributor

glensc commented May 3, 2024

@ma-sadeghi did you update to 4.66.4?

@ma-sadeghi
Copy link

Yes, tqdm.__version__ shows 4.66.4.

@glensc
Copy link
Contributor

glensc commented May 4, 2024

works for me from terminal

$ python test_tqdm.py
/lib/python3.8/site-packages/tqdm/rich.py:146: TqdmExperimentalWarning: rich is experimental/alpha
  return tqdm_rich(range(*args), **kwargs)
i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7
i=8
i=9
 100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10/10  [ 0:00:01 < 0:00:00 , 9 it/s ]
finished
$
Source
# https://github.com/tqdm/tqdm/issues/1306#issuecomment-2092369446
from tqdm.rich import trange, tqdm
import time

it = trange(10)
for i in it:
    print(f"i={i}")
    time.sleep(0.1)

print("finished")

@ma-sadeghi
Copy link

Right, but as I mentioned, it doesn't work in the Interactive Window. Ctrl shift P, then look for Interactive Window, then run the snippet there

@glensc
Copy link
Contributor

glensc commented May 5, 2024

looks good to me

image

imho what you're experimenting is a different issue. probably in vscode or terminal or os.

when creating new bugreport include all details of your system, os/terminal ($TERM), etc. maybe include a screenshot or video if can't present as text.

@ma-sadeghi
Copy link

There you go:

Code_oQaD1yB10l.mp4

@glensc
Copy link
Contributor

glensc commented May 7, 2024

@ma-sadeghi see this comment, maybe this applies to you:

@ma-sadeghi
Copy link

Thanks for the useful link. Indeed, if I pass refresh=True, my issue goes away. Basically, this line needs to be patched:

self._prog.update(self._task_id, completed=self.n, description=self.desc)

with refresh=True. Does that make sense?

@glensc
Copy link
Contributor

glensc commented May 7, 2024

so, that's two users, previous user didn't provide reproducer (if you read that link I shared). so submit pr with a fix and fingers crossed that maintainer will accept it soon :)

@ma-sadeghi
Copy link

@glensc Right, I'll submit a PR soon. Thanks for helping figure out the root cause :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-bug-warning ⚠ Visual output bad submodule ⊂ Periphery/subclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants