Skip to content

Commit

Permalink
On Python 3.11 _fork_exec now needs to be monkey-patched for subproce…
Browse files Browse the repository at this point in the history
…sses.
  • Loading branch information
fabioz committed Nov 18, 2022
1 parent 4067700 commit 79b81bb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,38 @@ def new_warn_fork_exec(*args):
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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 79b81bb

Please sign in to comment.