Skip to content

Commit f4b36c7

Browse files
committed
fix return tracker for multiple threads
1 parent 557a6f1 commit f4b36c7

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

python/code/wypp/stacktrace.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import traceback
33
import utils
44
import inspect
5+
import threading
56
from typing import Optional, Any
67
import os
78
import sys
89
from collections import deque
10+
from myLogging import *
911

1012
def tbToFrameList(tb: types.TracebackType) -> list[types.FrameType]:
1113
cur = tb
@@ -130,5 +132,12 @@ def getReturnTracker():
130132
obj = sys.getprofile()
131133
if isinstance(obj, ReturnTracker):
132134
return obj
135+
elif obj is None:
136+
if threading.current_thread() is threading.main_thread():
137+
raise ValueError(f'No ReturnTracker set, must use installProfileHook before')
138+
else:
139+
debug('ReturnTracker not available in threads')
140+
return None
133141
else:
134-
raise ValueError(f'No ReturnTracker set, must use installProfileHook before')
142+
debug(f'Profiling set to some custom profiler: {obj}')
143+
return None

python/code/wypp/typecheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def wrapped(*args, **kwargs) -> T:
253253
utils._call_with_frames_removed(checkArguments, sig, args, kwargs, info, checkCfg)
254254
returnTracker = stacktrace.getReturnTracker()
255255
result = utils._call_with_next_frame_removed(f, *args, **kwargs)
256-
ft = returnTracker.getReturnFrameType(0)
256+
ft = returnTracker.getReturnFrameType(0) if returnTracker else None
257257
utils._call_with_frames_removed(
258258
checkReturn, sig, ft, result, info, checkCfg
259259
)

0 commit comments

Comments
 (0)