Skip to content

Instantly share code, notes, and snippets.

@Kyuuhachi
Created May 6, 2020 10:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kyuuhachi/c983e590a7257f79d97b2fd935779e9d to your computer and use it in GitHub Desktop.
Save Kyuuhachi/c983e590a7257f79d97b2fd935779e9d to your computer and use it in GitHub Desktop.
import sys
if not sys.gettrace():
# f_trace doesn't work if settrace isn't set
sys.settrace(lambda a, b, c: None)
def j(n):
def hook(fr, event, arg):
assert event == "opcode"
fr.f_lineno += n
fr.f_trace = oldhook
fr.f_trace_opcodes = oldtraceops
if oldtraceops and oldhook:
return oldhook(fr, event, arg)
fr = sys._getframe().f_back
oldhook = fr.f_trace
oldtraceops = fr.f_trace_opcodes
fr.f_trace = hook
fr.f_trace_opcodes = True
a = 1
j(3)
a = 2
print(1)
print(2)
if a == 1:
j(-4)
print(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment