Support capturing interactive progress bar
See original GitHub issueI am using tqdm
which interactively update the progress bar in the terminal.
A sacred observer captures stdout like this:
[train] loss = 0.0000 acc = 1.0000: 2%|▏ | 29/1500 [00:01<11:18, 2.17it/s]
[train] loss = 0.0002 acc = 1.0000: 2%|▏ | 29/1500 [00:01<11:18, 2.17it/s]
[train] loss = 0.0002 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0041 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0002 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0045 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0003 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:52, 3.08it/s]
[train] loss = 0.0003 acc = 1.0000: 4%|▍ | 58/1500 [00:01<05:31, 4.35it/s]
[train] loss = 0.0000 acc = 1.0000: 4%|▍ | 58/1500 [00:01<05:31, 4.35it/s]
Applying ex.captured_out_filter = apply_backspaces_and_linefeeds
has no effect.
If I have a nested tqdm (two for-loops),
[train] loss = 0.0000 acc = 1.0000: 2%|▏ | 30/1500 [00:01<10:54, 2.25it/s][A
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:36, 3.19it/s][A
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:36, 3.19it/s][A
[train] loss = 0.0000 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:36, 3.19it/s][A
[train] loss = 0.0001 acc = 1.0000: 3%|▎ | 45/1500 [00:01<07:36, 3.19it/s][A
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:8 (1 by maintainers)
Top Results From Across the Web
10 inspiring progress bars that delight users
Progress bars set expectations, give an impression of activity and can calm users. Here are 10 that do it right.
Read more >Applying or Capturing Image No Progress Bar Movement
During the applying image or capturing image step the progress bar remains stuck at 0% for about 15 minutes then bounces all the...
Read more >Using a Progress Bar (UI) in SaaS-Types and Examples
A progress bar (UI) is a tool to boost engagement and reduce friction in SaaS. Here's how you should use them, and how...
Read more >How to create a Cross-browser Compatible HTML ...
Learn about HTML5 Progress Bar, its elements, the best way to style it using CSS, and solutions for cross-browser compatibility issues.
Read more >ProgressBar
Progress bar supports two modes to represent progress: determinate, ... Automatically determine whether a view is important for content capture.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I managed to fix the TQDM issue with multiple lines, but not the color issue. To fix, use:
From what I understand: If you don’t do this, tqdm will detect that you are using a terminal (
SETTINGS.CAPTURE_MODE = 'fd'
which is the default in linux) and that it’s possible to move the cursor inside this terminal. So tqdm will use\n
and move the cursor. By usingSETTINGS.CAPTURE_MODE = 'sys'
, tqdm understands that it has to write inside a text stream and that it can’t control the cursor. It then uses\r
to come back at the start of the line. This use case is then handled correctly byapply_backspaces_and_linefeeds
. Given how the capture works, I believe it’s impossible to make it work with nested progress bars in TQDM. Colored output is another problem which is unrelated to this fix.Feel free to correct me. This comes from my limited knowledge of linux, shells and streams.
If you’re using Python 3, this issue may be because the captured output has all of its carriage returns (
\r
) converted to new lines (\n
). I’ve submitted this bug report (above).This quick fix has worked for me:
Try altering line 119 in stdout_capturing.py to be
with NamedTemporaryFile(mode="w+", newline='') as target:
. You’ll still need to applyex.captured_out_filter = apply_backspaces_and_linefeeds
, but you won’t need to changeSETTINGS.CAPTURE_MODE
.