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

[BUG] Progress bar data is not piped when a script using rich is run in a subprocess #2326

Closed
joeyballentine opened this issue Jun 6, 2022 · 5 comments

Comments

@joeyballentine
Copy link

joeyballentine commented Jun 6, 2022

Describe the bug

Progress bar updates are not piped via stdout when running any script that uses rich in a subprocess. I specifically noticed this when trying to parse the progress bar of a pip install (pip uses rich for its progress bar), when I noticed that it only pipes the data of the final (finished) bar, and none of the updates.

This stack overflow post I found describes the issue in slightly more detail and provides a minimal repro. They mention using python's Popen, but the same thing happens in nodejs's child_process.spawn function.

Here's an example of what it outputs:

Collecting onnx\r\n
  Downloading onnx-1.11.0-cp39-cp39-win_amd64.whl (11.2 MB)\r\n
---------------------------------------- 11.2/11.2 MB 6.7 MB/s eta 0:00:00\r\n

And what I would expect it to output:

Collecting onnx\r\n
  Downloading onnx-1.11.0-cp39-cp39-win_amd64.whl (11.2 MB)\r\n
     -                                        1.0/11.2 MB 6.7 MB/s eta 0:01:00\r\n
     ----                                     2.2/11.2 MB 6.7 MB/s eta 0:00:50\r\n
     ------------                             6.8/11.2 MB 6.7 MB/s eta 0:00:30\r\n
     ---------------------------              8.2/11.2 MB 6.7 MB/s eta 0:00:20\r\n
     ------------------------------------     10.0/11.2 MB 6.7 MB/s eta 0:00:10\r\n
     ---------------------------------------- 11.2/11.2 MB 6.7 MB/s eta 0:00:00\r\n

Platform
Windows

P.S. Please don't tell me not to run pip install commands this way. I have a specific use case and it will be a waste of time to argue about this. This is a general issue that extends far beyond pip, and I'm sure being able to parse progress bars from scripts is helpful to more people than just me.

@willmcgugan
Copy link
Collaborator

Rich will strip anything dynamic when it detects it is not writing to a console.

If you don't want this you can force it to behave as a terminal with force_terminal=True. However, since you don't control that, you should consider using a psuedo-terminal rather than a subprocess.

@joeyballentine
Copy link
Author

Thanks for the response. For now, I will use a pseudo-terminal, and I will see if the pip team is open to making force_terminal an option.

@github-actions
Copy link

github-actions bot commented Jun 6, 2022

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

@joeyballentine
Copy link
Author

@willmcgugan sorry to revive this issue, but is there any chance you'd consider adding the ability to use an environment variable to force this instead of needing to change every codebase that uses rich?

@willmcgugan
Copy link
Collaborator

Potentially. See pypa/pip#10909 for background

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants