fix AttributeError 'fp' for `tqdm.write()`

- fixes #383
This commit is contained in:
Casper da Costa-Luis 2018-04-25 18:19:12 +01:00
parent 7f1590e27e
commit 61b116cea4
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
1 changed files with 7 additions and 9 deletions

View File

@ -483,16 +483,14 @@ class tqdm(object):
# 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()
@ -843,10 +841,10 @@ class tqdm(object):
# 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