Skip to content

Commit c8e2704

Browse files
committed
catch AttributeError only and return early from _stop if _pid is None
1 parent 5d6c9b3 commit c8e2704

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Lib/multiprocessing/resource_tracker.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,27 @@ def __del__(self):
7979
# making sure child processess are cleaned before ResourceTracker
8080
# gets destructed.
8181
# see https://github.com/python/cpython/issues/88887
82-
self._stop()
82+
try:
83+
self._stop()
84+
except AttributeError:
85+
# AttributeError is likely caused by module teardown
86+
# > __del__() can be executed during interpreter shutdown. As a
87+
# > consequence, the global variables it needs to access (including
88+
# > other modules) may already have been deleted or set to None.
89+
# see https://docs.python.org/3/reference/datamodel.html#object.__del__
90+
pass
8391

8492
def _stop(self):
8593
with self._lock:
86-
if self._pid is None:
87-
return
8894
# This should not happen (_stop() isn't called by a finalizer)
8995
# but we check for it anyway.
9096
if self._lock._recursion_count() > 1:
9197
return self._reentrant_call_error()
9298
if self._fd is None:
9399
# not running
94100
return
101+
if self._pid is None:
102+
return
95103

96104
# closing the "alive" file descriptor stops main()
97105
os.close(self._fd)

0 commit comments

Comments
 (0)