fix monitor `RuntimeError`

- fixes #481
This commit is contained in:
Casper da Costa-Luis 2021-08-23 16:10:25 +01:00
parent 140c94855b
commit b6326c27ed
No known key found for this signature in database
GPG Key ID: F5126E5FBD2512AD
1 changed files with 9 additions and 4 deletions

View File

@ -45,10 +45,15 @@ class TMonitor(Thread):
return self.report()
def get_instances(self):
# returns a copy of started `tqdm_cls` instances
return [i for i in self.tqdm_cls._instances.copy()
# Avoid race by checking that the instance started
if hasattr(i, 'start_t')]
"""returns a copy of started `tqdm_cls` instances"""
for _ in range(3): # retry
try:
return [i for i in self.tqdm_cls._instances.copy()
# Avoid race by checking that the instance started
if hasattr(i, 'start_t')]
except RuntimeError:
pass
return []
def run(self):
cur_t = self._time()