On Python 3.11 _fork_exec now needs to be monkey-patched for subprocesses.
@@ -850,6 +850,38 @@ def create_warn_fork_exec(original_name):
return new_warn_fork_exec
+def create_subprocess_fork_exec(original_name):
+ """
+ subprocess._fork_exec(args, executable_list, close_fds, ... (13 more))
+ """
+
+ def new_fork_exec(args, *other_args):
+ import subprocess
+ if _get_apply_arg_patching():
+ args = patch_args(args)
+ send_process_created_message()
+
+ return getattr(subprocess, original_name)(args, *other_args)
+
+ return new_fork_exec
+
+
+def create_subprocess_warn_fork_exec(original_name):
+ """
+ subprocess._fork_exec(args, executable_list, close_fds, ... (13 more))
+ """
+
+ def new_warn_fork_exec(*args):
+ try:
+ import subprocess
+ warn_multiproc()
+ return getattr(subprocess, original_name)(*args)
+ except:
+ pass
+
+ return new_warn_fork_exec
+
+
def create_CreateProcess(original_name):
"""
CreateProcess(*args, **kwargs)
@@ -986,6 +1018,12 @@ def patch_new_process_functions():
monkey_patch_module(_posixsubprocess, 'fork_exec', create_fork_exec)
except ImportError:
pass
+
+ try:
+ import subprocess
+ monkey_patch_module(subprocess, '_fork_exec', create_subprocess_fork_exec)
+ except AttributeError:
+ pass
else:
# Windows
try:
@@ -1022,6 +1060,13 @@ def patch_new_process_functions_with_warning():
monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
except ImportError:
pass
+
+ try:
+ import subprocess
+ monkey_patch_module(subprocess, '_fork_exec', create_subprocess_warn_fork_exec)
+ except AttributeError:
+ pass
+
else:
# Windows
try:
