MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / new_fork

Function new_fork

_pydev_bundle/pydev_monkey.py:933–971  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

931
932def create_fork(original_name):
933 def new_fork():
934 # A simple fork will result in a new python process
935 is_new_python_process = True
936 frame = sys._getframe()
937
938 apply_arg_patch = _get_apply_arg_patching()
939
940 is_subprocess_fork = False
941 while frame is not None:
942 if frame.f_code.co_name == "_execute_child" and "subprocess" in frame.f_code.co_filename:
943 is_subprocess_fork = True
944 # If we're actually in subprocess.Popen creating a child, it may
945 # result in something which is not a Python process, (so, we
946 # don't want to connect with it in the forked version).
947 executable = frame.f_locals.get("executable")
948 if executable is not None:
949 is_new_python_process = False
950 if is_python(executable):
951 is_new_python_process = True
952 break
953
954 frame = frame.f_back
955 frame = None # Just make sure we don't hold on to it.
956
957 protocol = pydevd_constants.get_protocol()
958 debug_mode = PydevdCustomization.DEBUG_MODE
959
960 child_process = getattr(os, original_name)() # fork
961 if not child_process:
962 if is_new_python_process:
963 PydevdCustomization.DEFAULT_PROTOCOL = protocol
964 PydevdCustomization.DEBUG_MODE = debug_mode
965 _on_forked_process(setup_tracing=apply_arg_patch and not is_subprocess_fork)
966 else:
967 set_global_debugger(None)
968 else:
969 if is_new_python_process:
970 send_process_created_message()
971 return child_process
972
973 return new_fork
974

Callers

nothing calls this directly

Calls 6

set_global_debuggerFunction · 0.90
_get_apply_arg_patchingFunction · 0.85
is_pythonFunction · 0.85
_on_forked_processFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected