forked from ionelmc/python-hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplepdb.py
More file actions
56 lines (40 loc) · 1.04 KB
/
samplepdb.py
File metadata and controls
56 lines (40 loc) · 1.04 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import sys
import hunter
def on_postmortem():
print('Raising stuff ...', os.getpid())
try:
raise Exception("BOOM!")
except Exception:
pdb.post_mortem()
def on_settrace():
print('Doing stuff ...', os.getpid())
pdb.set_trace()
def one():
for i in range(2): # one
two()
def two():
for i in range(2): # two
three()
def three():
print('Debugme!')
def on_debugger():
one()
if __name__ == '__main__':
if sys.argv[1] == 'pdb':
import pdb
from pdb import Pdb
elif sys.argv[1] == 'ipdb':
import ipdb as pdb
Pdb = lambda: pdb
if sys.argv[2] == 'debugger':
with hunter.trace(source__has='Debugme!', action=hunter.Debugger(Pdb)):
on_debugger()
else:
with hunter.trace(module='samplepdb'):
if sys.argv[2] == 'postmortem':
on_postmortem()
elif sys.argv[2] == 'settrace':
on_settrace()
else:
raise RuntimeError(sys.argv)