You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would make sense for this to exist within debugpy directly. If this is not of interest, I still would like to keep this issue here so people can see how I handled it. To the best of my knowledge I couldn't find anything this simple.
I've been using the following to trigger postmortem debugging when debugging code in the vscode debugger:
importsysimportthreadingdefmaybe_debugpy_postmortem(excinfo):
"""Make the debugger enter and stop at a raised exception. excinfo: A (type(e), e, e.__traceback__) tuple. See sys.exc_info() """exc_type, exc_value, exc_tb=excinfotry:
importdebugpyimportpydevd# type: ignoreexceptImportError:
# If pydevd isn't available, no debugger attached; do nothing.returnifnotdebugpy.is_client_connected():
returnpy_db=pydevd.get_global_debugger()
thread=threading.current_thread()
additional_info=py_db.set_additional_thread_info(thread)
additional_info.is_tracing+=1try:
py_db.stop_on_unhandled_exception(py_db, thread, additional_info, excinfo)
finally:
additional_info.is_tracing-=1defdebugpy_pm_tb():
maybe_debugpy_postmortem(sys.exc_info())
This no longer works since python 3.12, with the new sys.monitoring system. Because the embedded pydevd does not use is_tracing as a reentrancy guard any more with sys.monitoring, this results in the pydevd triggering a LINE event (from certain modules that aren't in the pydevd_dont_trace_files.py: json.init, json.encoder, contextlib, tokenize) in the middle of the process of suspending, which tries to call do_wait_suspend inside itself and breaks everything. I've been unable to decipher how exactly it prevents this from happening when postmortem debugging is triggered normally, from an unhandled exception escaping the program.
A simple postmortem debugging function that just works would be really nice...
Activity
nshepperd commentedon Jan 31, 2026
I've been using the following to trigger postmortem debugging when debugging code in the vscode debugger:
This no longer works since python 3.12, with the new sys.monitoring system. Because the embedded pydevd does not use is_tracing as a reentrancy guard any more with sys.monitoring, this results in the pydevd triggering a LINE event (from certain modules that aren't in the pydevd_dont_trace_files.py: json.init, json.encoder, contextlib, tokenize) in the middle of the process of suspending, which tries to call do_wait_suspend inside itself and breaks everything. I've been unable to decipher how exactly it prevents this from happening when postmortem debugging is triggered normally, from an unhandled exception escaping the program.
A simple postmortem debugging function that just works would be really nice...
nshepperd commentedon Jan 31, 2026
the following nonsense works, but only if env variable PYDEVD_USE_CYTHON=NO is set before loading:
it's not great