forked from jrfonseca/gprof2dot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.py
36 lines (26 loc) · 945 Bytes
/
debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''Debugging utilities.'''
import sys
import traceback
import inspect
def excepthook(type, value, tb):
"""
Automatically start the debugger on an exception.
See also:
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287
"""
if hasattr(sys, 'ps1') \
or not (sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) \
or type == SyntaxError or type == KeyboardInterrupt:
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
oldexcepthook(type, value, tb)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(type, value, tb)
print
# ...then start the debugger in post-mortem mode.
pdb.pm()
oldexcepthook, sys.excepthook = sys.excepthook, excepthook
def dump(var):
sys.stderr.write(repr(var) + '\n')