From a3477060f1974ef1413e5a2108fbdf60d4299be0 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 14:49:53 +0100 Subject: [PATCH] potential thread safety fix - related: #548 --- tqdm/std.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tqdm/std.py b/tqdm/std.py index 26baea04..e93590ff 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -1022,9 +1022,13 @@ class tqdm(Comparable): def __enter__(self): return self - def __exit__(self, *exc): - self.close() - return False + def __exit__(self, exc_type, exc_value, traceback): + try: + self.close() + except AttributeError: + # maybe eager thread cleanup upon external error + if exc_type is None: + raise def __del__(self): self.close()