Skip to content

Instantly share code, notes, and snippets.

@umyuu
Created May 7, 2018 05:44
Show Gist options
  • Save umyuu/594059d431558346218b87784a2d98ce to your computer and use it in GitHub Desktop.
Save umyuu/594059d431558346218b87784a2d98ce to your computer and use it in GitHub Desktop.
```Python
def trace_calls(frame, event, arg):
if event != 'line':
return trace_calls
from functools import lru_cache
from linecache import getline
@lru_cache(maxsize=128)
def line_cache(filename: str, line_no: int):
return getline(filename, line_no).rstrip()
co_filename: str = frame.f_code.co_filename
if co_filename != __file__:
return trace_calls
lineno: int = frame.f_lineno
print(line_cache(co_filename, lineno))
return trace_calls
sys.settrace(trace_calls)
# 無限ループになる処理
#
sys.settrace(None)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment