1 '''Debugging utilities.'''
9 def excepthook(type, value, tb):
11 Automatically start the debugger on an exception.
14 - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287
17 if hasattr(sys, 'ps1') \
18 or not (sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) \
19 or type == SyntaxError or type == KeyboardInterrupt:
20 # we are in interactive mode or we don't have a tty-like
21 # device, so we call the default hook
22 oldexcepthook(type, value, tb)
25 # we are NOT in interactive mode, print the exception...
26 traceback.print_exception(type, value, tb)
28 # ...then start the debugger in post-mortem mode.
31 oldexcepthook, sys.excepthook = sys.excepthook, excepthook
35 sys.stderr.write(repr(var) + '\n')