Created
May 7, 2018 05:44
-
-
Save umyuu/594059d431558346218b87784a2d98ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```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