When creating a fork from a process in the debugger, we need to reset the whole debugger environment!
(setup_tracing=True)
| 3318 | |
| 3319 | |
| 3320 | def settrace_forked(setup_tracing=True): |
| 3321 | """ |
| 3322 | When creating a fork from a process in the debugger, we need to reset the whole debugger environment! |
| 3323 | """ |
| 3324 | from _pydevd_bundle.pydevd_constants import GlobalDebuggerHolder |
| 3325 | |
| 3326 | py_db = GlobalDebuggerHolder.global_dbg |
| 3327 | if py_db is not None: |
| 3328 | py_db.created_pydb_daemon_threads = {} # Just making sure we won't touch those (paused) threads. |
| 3329 | py_db = None |
| 3330 | |
| 3331 | GlobalDebuggerHolder.global_dbg = None |
| 3332 | threading.current_thread().additional_info = None |
| 3333 | |
| 3334 | # Make sure that we keep the same access tokens for subprocesses started through fork. |
| 3335 | setup = SetupHolder.setup |
| 3336 | if setup is None: |
| 3337 | setup = {} |
| 3338 | else: |
| 3339 | # i.e.: Get the ppid at this point as it just changed. |
| 3340 | # If we later do an exec() it should remain the same ppid. |
| 3341 | setup[pydevd_constants.ARGUMENT_PPID] = PyDevdAPI().get_ppid() |
| 3342 | access_token = setup.get("access-token") |
| 3343 | client_access_token = setup.get("client-access-token") |
| 3344 | |
| 3345 | if setup_tracing: |
| 3346 | from _pydevd_frame_eval.pydevd_frame_eval_main import clear_thread_local_info |
| 3347 | |
| 3348 | host, port = dispatch() |
| 3349 | |
| 3350 | import pydevd_tracing |
| 3351 | |
| 3352 | pydevd_tracing.restore_sys_set_trace_func() |
| 3353 | |
| 3354 | if setup_tracing: |
| 3355 | if port is not None: |
| 3356 | custom_frames_container_init() |
| 3357 | |
| 3358 | if clear_thread_local_info is not None: |
| 3359 | clear_thread_local_info() |
| 3360 | |
| 3361 | if PYDEVD_USE_SYS_MONITORING: |
| 3362 | pydevd_sys_monitoring.reset_thread_local_info() |
| 3363 | |
| 3364 | settrace( |
| 3365 | host, |
| 3366 | port=port, |
| 3367 | suspend=False, |
| 3368 | trace_only_current_thread=False, |
| 3369 | overwrite_prev_trace=True, |
| 3370 | patch_multiprocessing=True, |
| 3371 | access_token=access_token, |
| 3372 | client_access_token=client_access_token, |
| 3373 | ) |
| 3374 | |
| 3375 | |
| 3376 | @contextmanager |