[Python-checkins] gh-104536: Improve `multiprocessing.process._cleanup` logic (#104537)
gpshead
webhook-mailer at python.org
Sun May 21 23:49:13 EDT 2023
https://github.com/python/cpython/commit/ef5d00a59207a63c6d5ae0d5d44054847d1bf3b5
commit: ef5d00a59207a63c6d5ae0d5d44054847d1bf3b5
branch: main
author: Luccccifer <lukezhang764 at gmail.com>
committer: gpshead <greg at krypto.org>
date: 2023-05-22T03:48:57Z
summary:
gh-104536: Improve `multiprocessing.process._cleanup` logic (#104537)
Fix a race condition in the internal `multiprocessing.process` cleanup
logic that could manifest as an unintended `AttributeError` when calling
`BaseProcess.close()`.
---------
Co-authored-by: Oleg Iarygin <oleg at arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg at krypto.org>
files:
A Misc/NEWS.d/next/Library/2023-05-16-10-07-16.gh-issue-104536.hFWD8f.rst
M Lib/multiprocessing/process.py
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py
index c03c859baa79..271ba3fd3251 100644
--- a/Lib/multiprocessing/process.py
+++ b/Lib/multiprocessing/process.py
@@ -61,7 +61,7 @@ def parent_process():
def _cleanup():
# check for processes which have finished
for p in list(_children):
- if p._popen.poll() is not None:
+ if (child_popen := p._popen) and child_popen.poll() is not None:
_children.discard(p)
#
diff --git a/Misc/NEWS.d/next/Library/2023-05-16-10-07-16.gh-issue-104536.hFWD8f.rst b/Misc/NEWS.d/next/Library/2023-05-16-10-07-16.gh-issue-104536.hFWD8f.rst
new file mode 100644
index 000000000000..b0f5d78f7e61
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-05-16-10-07-16.gh-issue-104536.hFWD8f.rst
@@ -0,0 +1,3 @@
+Fix a race condition in the internal :mod:`multiprocessing.process` cleanup
+logic that could manifest as an unintended ``AttributeError`` when calling
+``process.close()``.
More information about the Python-checkins
mailing list