-
-
Couldn't load subscription status.
- Fork 1.4k
Open
Labels
duplicate 🗐Seen it beforeSeen it beforep2-bug-warning ⚠Visual output badVisual output badp4-enhancement-future 🧨On the back burnerOn the back burnerquestion/docs ‽Documentation clarification candidateDocumentation clarification candidateto-fix ⌛In progressIn progress
Milestone
Description
tqdm v. 4.31.1
Python v. 3.7.0
Linux version : Debian stretch (this bug does not reproduce on MacOs or ArchLinux)
When using tqdm with logging, configured as @casperdcl suggests it in #313 BUT with a line feed in the message, tqdm eats the new line.
Test code:
import tqdm
import logging
import time
class TqdmStream(object):
@classmethod
def write(_, msg):
tqdm.tqdm.write(msg, end='')
# is this required?
# @classmethod
# def flush(_):
# pass
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, stream=TqdmStream)
log = logging.getLogger(__name__)
log.info("loop")
# for x in tqdm.trange(1, 101, mininterval=10):
for x in tqdm.trange(1, 101):
time.sleep(.2)
if not x % 20:
log.debug("in loop %d\nnew line" % x)
log.info("done")
Now, several test cases:
- If a
\nis added to the end of the message, the text now gets displayed properly (with the line feed at the end, but we asked for it) - If we use
end="\n"instead ofend="", the message gets displayed properly but with two line feeds at the end. - passing
end="test"shows that tqdm seems to have an issue with stdout buffering, since it appends "test" to the next logging line (probably an issue on itself, not sure how it's related to this issue)
One might think that this is a flushing issue, but adding the following solves the 3rd test case (while breaking the progress bar though), while doing nothing for the 2nd one (not even breaking the progress bar).
import sys
class TqdmStream(object):
@classmethod
def write(_, msg):
tqdm.tqdm.write(msg, end='')
@classmethod
def flush(_):
sys.sdout.flush()
LinqLover
Metadata
Metadata
Assignees
Labels
duplicate 🗐Seen it beforeSeen it beforep2-bug-warning ⚠Visual output badVisual output badp4-enhancement-future 🧨On the back burnerOn the back burnerquestion/docs ‽Documentation clarification candidateDocumentation clarification candidateto-fix ⌛In progressIn progress