You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In particular you need calling_frame.f_trace = previous_tracein addition to the existing sys.settrace(previous_trace).
This is obviously good for restoring the other tracer properly, which I confirmed with the PyCharm debugger. But I stumbled across this because pp stopped working after with snoop: exited. It turns out that if you don't reset f_trace then the frame line number becomes wrong. Here's a demo:
importinspectimportpysnooperwithpysnooper.snoop():
passprint(inspect.currentframe().f_trace)
print(inspect.currentframe().f_lineno) # wrong lineno1/0# wrong lineno in traceback
In particular note the weird traceback:
Traceback (most recent call last):
File "...", line 5, in <module>passZeroDivisionError: division by zero
See alexmojaki/snoop#34
Basically you need to do this:
https://github.com/alexmojaki/snoop/blob/437956c661184ab458a3f60fcf97c81c31ea2db1/snoop/tracer.py#L213-L217
In particular you need
calling_frame.f_trace = previous_trace
in addition to the existingsys.settrace(previous_trace)
.This is obviously good for restoring the other tracer properly, which I confirmed with the PyCharm debugger. But I stumbled across this because
pp
stopped working afterwith snoop:
exited. It turns out that if you don't resetf_trace
then the frame line number becomes wrong. Here's a demo:In particular note the weird traceback:
Here's a pure python version of the demo:
This is a bug which is apparently fixed in 3.10: https://bugs.python.org/issue42823
The text was updated successfully, but these errors were encountered: