cleaner solution

This commit is contained in:
Casper da Costa-Luis 2016-07-18 21:36:15 +01:00
parent 5fbbd7369b
commit 1fd2234a0b
1 changed files with 8 additions and 9 deletions

View File

@ -308,15 +308,14 @@ class tqdm(object):
# Clear all bars
inst_cleared = []
if hasattr(cls, '_instances'):
for inst in cls._instances:
# Clear instance if in the target output file
# or if write output + tqdm output are both either
# sys.stdout or sys.stderr (because both are mixed in terminal)
if inst.fp == fp or all(f in (sys.stdout, sys.stderr)
for f in (fp, inst.fp)):
inst.clear()
inst_cleared.append(inst)
for inst in getattr(cls, '_instances', []):
# Clear instance if in the target output file
# or if write output + tqdm output are both either
# sys.stdout or sys.stderr (because both are mixed in terminal)
if inst.fp == fp or all(f in (sys.stdout, sys.stderr)
for f in (fp, inst.fp)):
inst.clear()
inst_cleared.append(inst)
# Write the message
fp.write(s)
fp.write(end)