[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 ef5d00a59207a63c6d5ae0d5d44054847d1bf3b5)

Co-authored-by: Luccccifer <lukezhang764@gmail.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2 files changed