gh-90549: Fix leak of global named resources using multiprocessing spawn (GH-30617)

Co-authored-by: XD Trol <milestonejxd@gmail.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
(cherry picked from commit 30610d2837)

Co-authored-by: Leo Trol <milestone.jxd@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-06-10 08:04:55 -07:00 committed by GitHub
parent 62cae22c0d
commit aee7d3df1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 2 deletions

View file

@ -304,8 +304,7 @@ class BaseProcess(object):
if threading._HAVE_THREAD_NATIVE_ID:
threading.main_thread()._set_native_id()
try:
util._finalizer_registry.clear()
util._run_after_forkers()
self._after_fork()
finally:
# delay finalization of the old process object until after
# _run_after_forkers() is executed
@ -336,6 +335,13 @@ class BaseProcess(object):
return exitcode
@staticmethod
def _after_fork():
from . import util
util._finalizer_registry.clear()
util._run_after_forkers()
#
# We subclass bytes to avoid accidental transmission of auth keys over network
#