Skip to content

Commit a703b00

Browse files
committed
Avoid "name Exception is not defined" when exiting
At interpreter shutdown, the module's global variables are set to None before the module itself is released. __del__ methods may be called in those precarious circumstances, and should not rely on any global state.
1 parent 19a8a33 commit a703b00

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

dbutils/pooled_db.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def __del__(self):
389389
"""Delete the pool."""
390390
try:
391391
self.close()
392-
except Exception:
392+
except: # builtin Exceptions might not exist any more
393393
pass
394394

395395
def _wait_lock(self):
@@ -437,7 +437,7 @@ def __del__(self):
437437
"""Delete the pooled connection."""
438438
try:
439439
self.close()
440-
except Exception:
440+
except: # builtin Exceptions might not exist any more
441441
pass
442442

443443

@@ -524,5 +524,5 @@ def __del__(self):
524524
"""Delete the pooled connection."""
525525
try:
526526
self.close()
527-
except Exception:
527+
except: # builtin Exceptions might not exist any more
528528
pass

dbutils/pooled_pg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def __del__(self):
244244
"""Delete the pool."""
245245
try:
246246
self.close()
247-
except Exception:
247+
except: # builtin Exceptions might not exist any more
248248
pass
249249

250250

@@ -291,5 +291,5 @@ def __del__(self):
291291
"""Delete the pooled connection."""
292292
try:
293293
self.close()
294-
except Exception:
294+
except: # builtin Exceptions might not exist any more
295295
pass

dbutils/steady_db.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def __del__(self):
512512
"""Delete the steady connection."""
513513
try:
514514
self._close() # make sure the connection is closed
515-
except Exception:
515+
except: # builtin Exceptions might not exist any more
516516
pass
517517

518518

@@ -697,5 +697,5 @@ def __del__(self):
697697
"""Delete the steady cursor."""
698698
try:
699699
self.close() # make sure the cursor is closed
700-
except Exception:
700+
except: # builtin Exceptions might not exist any more
701701
pass

dbutils/steady_pg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,5 @@ def __del__(self):
324324
"""Delete the steady connection."""
325325
try:
326326
self._close() # make sure the connection is closed
327-
except Exception:
327+
except: # builtin Exceptions might not exist any more
328328
pass

0 commit comments

Comments
 (0)