[BUG] Progress bar data is not piped when a script using rich is run in a subprocess
See original GitHub issueDescribe 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.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Potentially. See https://github.com/pypa/pip/issues/10909 for background
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.