[3.11] gh-104536: Improve multiprocessing.process._cleanup logic (GH-104537) (#104737)

Fix a race condition in the internal `multiprocessing.process` cleanup
logic that could manifest as an unintended `AttributeError` when calling
`BaseProcess.close()`.

(cherry picked from commit ef5d00a592)

Co-authored-by: Luccccifer <lukezhang764@gmail.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Miss Islington (bot) 2023-05-22 03:49:33 -07:00 committed by GitHub
parent e95ca78fab
commit 6f94bbf77e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View 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)
#