Skip to content

Commit aaa8378

Browse files
committed
injecting os methods on _stop
1 parent 9fd5872 commit aaa8378

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

Lib/multiprocessing/resource_tracker.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,9 @@ 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-
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
82+
self._stop()
9183

92-
def _stop(self):
84+
def _stop(self, close=os.close, waitpid=os.waitpid, waitstatus_to_exitcode=os.waitstatus_to_exitcode):
9385
with self._lock:
9486
# This should not happen (_stop() isn't called by a finalizer)
9587
# but we check for it anyway.
@@ -102,15 +94,15 @@ def _stop(self):
10294
return
10395

10496
# closing the "alive" file descriptor stops main()
105-
os.close(self._fd)
97+
close(self._fd)
10698
self._fd = None
10799

108-
_, status = os.waitpid(self._pid, 0)
100+
_, status = waitpid(self._pid, 0)
109101

110102
self._pid = None
111103

112104
try:
113-
self._exitcode = os.waitstatus_to_exitcode(status)
105+
self._exitcode = waitstatus_to_exitcode(status)
114106
except ValueError:
115107
# os.waitstatus_to_exitcode may raise an exception for invalid values
116108
self._exitcode = None

0 commit comments

Comments
 (0)