Is there a way to return out of a function badfunc() using a tracer function tracer(), if we set sys.settrace(tracer). I want to count the number of lines that badfunc() executes, and return out of it if it executes more than a given amount of lines.
e.g:
def badfunc():
while True:
import time
time.sleep(1)
def tracer(*args):
counter += 1
if counter > MAX_NUMLINES:
return_from_badfunc()
return tracer
sys.settrace(tracer)
Thanks!