Skip to content

Commit 6afc2e7

Browse files
Only trigger events on thread calling start_trace
1 parent 8955d78 commit 6afc2e7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Lib/bdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import fnmatch
44
import sys
5+
import threading
56
import os
67
import weakref
78
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
@@ -37,9 +38,11 @@ def __init__(self):
3738
self._name = 'bdbtracer'
3839
self._tracefunc = None
3940
self._disable_current_event = False
41+
self._tracing_thread = None
4042

4143
def start_trace(self, tracefunc):
4244
self._tracefunc = tracefunc
45+
self._tracing_thread = threading.current_thread()
4346
curr_tool = sys.monitoring.get_tool(self._tool_id)
4447
if curr_tool is None:
4548
sys.monitoring.use_tool_id(self._tool_id, self._name)
@@ -58,6 +61,7 @@ def start_trace(self, tracefunc):
5861
sys.monitoring.set_events(self._tool_id, all_events)
5962

6063
def stop_trace(self):
64+
self._tracing_thread = None
6165
curr_tool = sys.monitoring.get_tool(self._tool_id)
6266
if curr_tool != self._name:
6367
return
@@ -79,6 +83,8 @@ def callback_wrapper(func):
7983

8084
@functools.wraps(func)
8185
def wrapper(self, *args):
86+
if self._tracing_thread != threading.current_thread():
87+
return
8288
try:
8389
frame = sys._getframe().f_back
8490
ret = func(self, frame, *args)

0 commit comments

Comments
 (0)