From 7f1590e27edccce502c58b5fedf14ada1a08eb3f Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 20 Apr 2018 23:59:50 +0100 Subject: [PATCH] solve missing "pos" AttributeError on initialisation - fixes #323 (probably) --- tqdm/_tqdm.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tqdm/_tqdm.py b/tqdm/_tqdm.py index 2674ddbb..098a2fab 100755 --- a/tqdm/_tqdm.py +++ b/tqdm/_tqdm.py @@ -424,7 +424,7 @@ class tqdm(object): def _get_free_pos(cls, instance=None): """Skips specified instance""" positions = set(abs(inst.pos) for inst in cls._instances - if inst is not instance) + if inst is not instance and hasattr(inst, "pos")) return min(set(range(len(positions) + 1)).difference(positions)) @classmethod @@ -842,10 +842,11 @@ class tqdm(object): # if nested, at initial sp() call we replace '\r' by '\n' to # not overwrite the outer progress bar - if position is None: - self.pos = self._get_free_pos(self) - else: # mark fixed positions as negative - self.pos = -position + with self._lock: + 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