d = {'_frame': frame}
d.update(frame.f_globals)
d.update(frame.f_locals)
i = code.InteractiveConsole(d)
message = """Signal received : entering python shell.
Traceback:
"""
message += ''.join(traceback.format_stack(frame))
i.interact(message)

def listen():
    signal.signal(signal.SIGUSR1, debug)
Showing the stack trace from a running Python application