Conversation
Codecov Report
@@ Coverage Diff @@
## master #1222 +/- ##
==========================================
- Coverage 89.88% 89.66% -0.23%
==========================================
Files 26 26
Lines 1721 1732 +11
Branches 286 287 +1
==========================================
+ Hits 1547 1553 +6
- Misses 128 133 +5
Partials 46 46 |
When using the logging redirection, logs will currently always be printed
to stdout, while the logging module default is to print to stderr.
Fix this by trying to inherit the stream from the existing handler, like
the code already does for the formatter.
Consider the following example:
import logging
import time
from tqdm.contrib.logging import tqdm_logging_redirect
log = logging.getLogger()
log.warning("start")
with tqdm_logging_redirect(range(int(4))) as pbar:
for i in pbar:
time.sleep(0.1)
log.warning(f"Step {i}")
log.warning("done")
Running this while redirecting stdout (`$ python3 log.py > /dev/null`)
without this patch will print:
$ venv/bin/python log.py > /dev/null
start
100%|████████████████████████████████████████████| 4/4 [00:00<00:00, 9.87it/s]
done
After this patch:
$ venv/bin/python log.py > /dev/null
start
Step 0
Step 1
Step 2
Step 3
100%|████████████████████████████████████████████| 4/4 [00:00<00:00, 9.83it/s]
done
Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Member
Author
|
/tag v4.62.1 1ac732c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
contrib.logging: inherit existing handler output stream (logging: inherit output stream from existing handler #1191)PermissionErrorby usingweakrefinDisableOnWriteError(Use weakref on tqdm instance in DisableOnWriteError #1207)contrib.telegramcreation rate limit handling (contrib.telegram: gracefully handle creation rate limit #1223, Avoid telegram limit hit #1221 <- Telegram "Too Many Requests" Error #1220, tqdm_telegram exhausts message quota because of frequent updates #1076)kerasdependencies (next release v4.62.1 #1222)contrib.telegram: gracefully handle creation rate limit #1223