Skip to content

Commit ee91cf9

Browse files
committed
Make sure tracer is really uninstalled (handles situation where threads would still have tracer on).
1 parent 4119d78 commit ee91cf9

9 files changed

Lines changed: 3550 additions & 3476 deletions

File tree

src/hunter/_event.c

Lines changed: 1102 additions & 1105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hunter/_predicates.c

Lines changed: 2002 additions & 2030 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hunter/_tracer.c

Lines changed: 411 additions & 335 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hunter/_tracer.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ cdef int trace_func(Tracer self, FrameType frame, int kind, PyObject *arg) excep
3232

3333
handler = self.handler
3434

35+
if handler is None: # the tracer was stopped
36+
# make sure it's uninstalled even for running threads
37+
if self.profiling_mode:
38+
PyEval_SetProfile(NULL, NULL)
39+
else:
40+
PyEval_SetTrace(NULL, NULL)
41+
return 0
42+
3543
if kind == 3 and self.depth > 0:
3644
self.depth -= 1
3745

src/hunter/vendor/_cymem/cymem.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/samplepdb.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def on_postmortem():
99
try:
1010
raise Exception("BOOM!")
1111
except Exception:
12-
pdb.pm()
12+
pdb.post_mortem()
1313

1414

1515
def on_settrace():
@@ -38,14 +38,16 @@ def on_debugger():
3838
if __name__ == '__main__':
3939
if sys.argv[1] == 'pdb':
4040
import pdb
41+
from pdb import Pdb
4142
elif sys.argv[1] == 'ipdb':
4243
import ipdb as pdb
44+
Pdb = lambda: pdb
4345

4446
if sys.argv[2] == 'debugger':
45-
with hunter.trace(source__has='Debugme!', action=hunter.Debugger(lambda: pdb)):
47+
with hunter.trace(source__has='Debugme!', action=hunter.Debugger(Pdb)):
4648
on_debugger()
4749
else:
48-
with hunter.trace():
50+
with hunter.trace(module='samplepdb'):
4951
if sys.argv[2] == 'postmortem':
5052
on_postmortem()
5153
elif sys.argv[2] == 'settrace':

tests/test_integration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from pprint import pprint
88

99
import pytest
10+
from process_tests import TestProcess
11+
from process_tests import dump_on_error
12+
from process_tests import wait_for_strings
1013

1114
from hunter import Backlog
1215
from hunter import CallPrinter
@@ -22,6 +25,7 @@
2225
from hunter import trace
2326
from hunter import wrap
2427

28+
from utils import TIMEOUT
2529
from utils import DebugCallPrinter
2630

2731
try:
@@ -763,3 +767,16 @@ def test_backlog_subprocess(LineMatcher):
763767
"depth=5 calls=16 *sample7args.py:34 line return i # five",
764768
"depth=4 calls=16 *sample7args.py:34 return <= five: 0",
765769
])
770+
771+
772+
@pytest.mark.parametrize('pdb', ['pdb', 'ipdb'])
773+
@pytest.mark.parametrize('mode', ['postmortem', 'settrace', 'debugger'])
774+
def test_pdb(LineMatcher, pdb, mode):
775+
with TestProcess('python', '-msamplepdb', pdb, mode, stdin=subprocess.PIPE) as target, dump_on_error(target.read):
776+
wait_for_strings(target.read, TIMEOUT, '-> ')
777+
target.proc.stdin.write('c\n')
778+
output = target.read()
779+
assert 'TypeError' not in output
780+
assert "'NoneType' object is not callable" not in output
781+
assert 'Disabling tracer because handler' not in output
782+
assert 'Traceback (most recent call last)' not in output

tests/test_remote.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import distutils.spawn
2-
import os
32
import platform
43
import signal
54
import sys
@@ -9,7 +8,7 @@
98
from process_tests import dump_on_error
109
from process_tests import wait_for_strings
1110

12-
TIMEOUT = int(os.getenv('HUNTER_TEST_TIMEOUT', 10))
11+
from utils import TIMEOUT
1312

1413
platform, distutils.spawn
1514

tests/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import os
2+
13
from hunter import CallPrinter
24

5+
TIMEOUT = int(os.getenv('HUNTER_TEST_TIMEOUT', 10))
36

47
class DebugCallPrinter(CallPrinter):
58
def __init__(self, suffix='', **kwargs):

0 commit comments

Comments
 (0)