This project has moved and is read-only. For the latest updates, please go here.

Suspending a process on an exception so I can attach a debugger later?

Nov 7, 2013 at 6:58 PM
I have a use-case where I have about 40 python processes running in parallel (each individually invoked from the command line) and sometimes, unpredictably and as a result of a race condition I'm having a hard time debugging, one of them will hit an exception.

Can you think of a strategy where I can do a just-in-time trap of the exception and suspend the process so I can attach the debugger and look at the stack? If I put a try-catch around the main routine I can do this but I lose all the stack information except for the stuff that's preserved inside the Exception object. Since the Exception is being raised from external code and it's being thrown from different places in my logic, I can't see an obvious way to make the Exception richer, either.
Nov 7, 2013 at 7:02 PM
How about sys.settrace + blocking on exception event?

Would probably need to inspect the call stack to filter out regular exceptions and narrow down onto the one that you are interested in.