]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104536: Improve `multiprocessing.process._cleanup` logic (#104537)
authorLuccccifer <lukezhang764@gmail.com>
Mon, 22 May 2023 03:48:57 +0000 (11:48 +0800)
committerGitHub <noreply@github.com>
Mon, 22 May 2023 03:48:57 +0000 (03:48 +0000)
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@arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Lib/multiprocessing/process.py
Misc/NEWS.d/next/Library/2023-05-16-10-07-16.gh-issue-104536.hFWD8f.rst [new file with mode: 0644]

index c03c859baa795bfc9be6a69e79f45f17f265f5be..271ba3fd325138d75a7707d97d89b7003c5fcbc4 100644 (file)
@@ -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 (file)
index 0000000..b0f5d78
--- /dev/null
@@ -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()``.