Skip to content

Commit

Permalink
cleaner solution
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jul 18, 2016
1 parent 5fbbd73 commit 1fd2234
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,14 @@ def write(cls, s, file=sys.stdout, end="\n"):

# 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)
Expand Down

0 comments on commit 1fd2234

Please sign in to comment.