Skip to content

Commit

Permalink
fix AttributeError 'fp' for tqdm.write()
Browse files Browse the repository at this point in the history
- fixes #383
  • Loading branch information
casperdcl committed Apr 25, 2018
1 parent 7f1590e commit 61b116c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,14 @@ def external_write_mode(cls, file=None, nolock=False):
# 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)):
if hasattr(inst, "start_t") and (inst.fp == fp or all(
f in (sys.stdout, sys.stderr) for f in (fp, inst.fp))):
inst.clear(nolock=True)
inst_cleared.append(inst)
yield
# Force refresh display of bars we cleared
for inst in inst_cleared:
# Avoid race conditions by checking that the instance started
if hasattr(inst, 'start_t'): # pragma: nocover
inst.refresh(nolock=True)
inst.refresh(nolock=True)
if not nolock:
cls._lock.release()

Expand Down Expand Up @@ -843,10 +841,10 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True,
# if nested, at initial sp() call we replace '\r' by '\n' to
# not overwrite the outer progress bar
with self._lock:
if position is None:
self.pos = self._get_free_pos(self)
else: # mark fixed positions as negative
self.pos = -position
if position is None:
self.pos = self._get_free_pos(self)
else: # mark fixed positions as negative
self.pos = -position

if not gui:
# Initialize the screen printer
Expand Down

0 comments on commit 61b116c

Please sign in to comment.