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

question: tqdm progress display keeps lines on the screen #14

Open
spock opened this issue Nov 12, 2023 · 3 comments
Open

question: tqdm progress display keeps lines on the screen #14

spock opened this issue Nov 12, 2023 · 3 comments
Assignees
Labels

Comments

@spock
Copy link

spock commented Nov 12, 2023

For all operations, there is a nice tqdm progress shown, but at least for me each update is printed as a new, separate line, instead of overwriting the same line over and over (which I believe is the default behavior of tqdm).

This results in lots of scrolling, pushing away more interesting messages (such as file date/checksum mismatches):

 99%|#########9| 48385/48771 [07:03<00:02, 179.60it/s]
 99%|#########9| 48403/48771 [07:03<00:02, 177.26it/s]
 99%|#########9| 48421/48771 [07:03<00:01, 175.20it/s]
 99%|#########9| 48439/48771 [07:03<00:01, 173.68it/s]
 99%|#########9| 48457/48771 [07:03<00:01, 173.15it/s]
 99%|#########9| 48475/48771 [07:03<00:01, 172.24it/s]
 99%|#########9| 48493/48771 [07:03<00:01, 172.36it/s]
 99%|#########9| 48511/48771 [07:04<00:01, 171.92it/s]

Is this behavior by design, or does it behave so only on my system?
pyFileFixity version 3.1.4 installed with pip, on Python 3.10.12, on WSL2.

@lrq3000
Copy link
Owner

lrq3000 commented Nov 12, 2023 via email

@spock
Copy link
Author

spock commented Nov 12, 2023

I'm using Windows Terminal, and trying pff in cmd, powershell, and git bash had exactly the same behavior as in WSL2 above.

I did find a number of issues mentioning tqdm and windows together, but none quite the same.

Strangely, running this example code in ipython3 (under WSL2) works as expected:

image

One more strange observation: if I specify --log option, then log files also has multiple tqdm lines, with clear newlines (as shown by less):

^M  1%|          | 244/48771 [00:11<11:51, 68.16it/s]
^M  1%|          | 252/48771 [00:11<11:20, 71.30it/s]

Wait, eureka?
I see that in lib/tee.py on line 37 (def write), you have end = "\n".
And ptee object is given to tqdm as a "file-like that supports write method".
However, normal write does NOT auto-append "\n"; could this be the problem?

If I do replace that "\n" with "", then tqdm status line looks/works exactly as it should... but of course all the other output is now mangled, because you expect an automatic newline with each ptee.write().

Actually, shouldn't tqdm write ONLY to stdout?
It makes no sense to write that to the log.

Indeed, replacing tqdm(..., file=ptee, ...) with tqdm(..., file=stdout, ...) in rfigs.py DOES fix the problem, at least as long as I don't specify --log (which redirects stdout and thus breaks output).

I'll probably give a "native Linux" pff a try tomorrow, I don't believe it works there with def write(..., end="\n", ...).

@lrq3000
Copy link
Owner

lrq3000 commented Nov 13, 2023 via email

@lrq3000 lrq3000 self-assigned this Nov 16, 2023
@lrq3000 lrq3000 added the bug label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants