Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # track_last_200.py
- import re
- import sys
- from functools import wraps
- import inspect
- last_200 = [''] * 200
- prev_line = dict([(k, None) for k in variables])
- def track_all_changes(variables_to_track):
- def slide(var, line):
- if prev_line[var] != line:
- last_200.append(line)
- last_200.pop(0)
- prev_line[var] = line
- def track_changes(func):
- @wraps(func)
- def wrapper(*args, **kwargs):
- tracked = []
- frame = inspect.currentframe()
- try:
- result = func(*args, **kwargs)
- except:
- for line in last_200:
- print(line)
- raise
- for k, v in frame.f_back.f_locals.items():
- if k in variables_to_track:
- slide(k, f"Local {k}: {v}")
- for k, v in frame.f_back.f_globals.items():
- if k in variables_to_track:
- slide(k, f"{func.__name__}() Global {k}: {v}")
- if tracked not in last_200:
- return result
- return wrapper
- module = sys.modules[__name__]
- for name, obj in inspect.getmembers(module):
- if re.sub(r'__[^>]*__', '', name):
- if inspect.isfunction(obj):
- setattr(module, name, track_changes(obj))
- track_all_changes(variables)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement