From b6326c27ed0a3295f836ca6f40dbbed817347aff Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 23 Aug 2021 16:10:25 +0100 Subject: [PATCH] fix monitor `RuntimeError` - fixes #481 --- tqdm/_monitor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tqdm/_monitor.py b/tqdm/_monitor.py index f8443bca..547cb3a8 100644 --- a/tqdm/_monitor.py +++ b/tqdm/_monitor.py @@ -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()