inducer / pudb

Full-screen console debugger for Python
https://documen.tician.de/pudb/
Other
2.99k stars 230 forks source link

RecursionError is not caught by the debugger #448

Open asmeurer opened 3 years ago

asmeurer commented 3 years ago

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.

inducer commented 3 years ago

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.

asmeurer commented 3 years ago

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?