Interrupt running process, and provide a python prompt for interactive debugging.
(sig, frame)
| 295 | # Getting stack trace from a running Python application |
| 296 | # http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application |
| 297 | def debug(sig, frame): |
| 298 | """Interrupt running process, and provide a python prompt for |
| 299 | interactive debugging.""" |
| 300 | d={'_frame':frame} # Allow access to frame object. |
| 301 | d.update(frame.f_globals) # Unless shadowed by global |
| 302 | d.update(frame.f_locals) |
| 303 | |
| 304 | i = code.InteractiveConsole(d) |
| 305 | message = "Signal recieved : entering python shell.\nTraceback:\n" |
| 306 | message += ''.join(traceback.format_stack(frame)) |
| 307 | i.interact(message) |
| 308 | |
| 309 | |
| 310 | def listen(): |