pudb icon indicating copy to clipboard operation
pudb copied to clipboard

RecursionError is not caught by the debugger

Open asmeurer opened this issue 3 years ago • 2 comments

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.

asmeurer avatar May 03 '21 23:05 asmeurer

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.

inducer avatar May 03 '21 23:05 inducer

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?

asmeurer avatar May 03 '21 23:05 asmeurer