pudb
pudb copied to clipboard
RecursionError is not caught by the debugger
With something like
def test():
raise ValueError
import pudb
pudb.set_trace()
test()
If you step over test()
, it tells you that an exception has been raised. But with
def test():
test()
import pudb
pudb.set_trace()
test()
The whole program exits with a traceback. In the case where you instead run python -m pudb file.py
, the RecursionError is caught, but as an "uncaught exception" (post mortem).
I browsed the pudb and bdb code and it isn't clear to me why this is happening.
The debugger tries to live on the same stack as the "debuggee" that just ran out of stack space. It's likely that the Python runtime enters the debugger, but then quickly runs out of stack again and thus crashing altogether.
Yeah, that sounds likely. I know you can definitely catch RecursionError in some instances. I've never really understood under what circumstances it does and doesn't work. Presumably Python allows some extra frames on RecursionError to potentially clean it up, but how many?