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

Co-authored-by: XD Trol <milestonejxd@gmail.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
This commit is contained in:
Leo Trol 2022-06-10 00:55:12 +08:00 committed by GitHub
parent 6099611af5
commit 30610d2837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 2 deletions

View file

@ -223,6 +223,10 @@ class Process(process.BaseProcess):
def _Popen(process_obj):
return _default_context.get_context().Process._Popen(process_obj)
@staticmethod
def _after_fork():
return _default_context.get_context().Process._after_fork()
class DefaultContext(BaseContext):
Process = Process
@ -283,6 +287,11 @@ if sys.platform != 'win32':
from .popen_spawn_posix import Popen
return Popen(process_obj)
@staticmethod
def _after_fork():
# process is spawned, nothing to do
pass
class ForkServerProcess(process.BaseProcess):
_start_method = 'forkserver'
@staticmethod
@ -326,6 +335,11 @@ else:
from .popen_spawn_win32 import Popen
return Popen(process_obj)
@staticmethod
def _after_fork():
# process is spawned, nothing to do
pass
class SpawnContext(BaseContext):
_name = 'spawn'
Process = SpawnProcess