Created
March 7, 2020 01:57
-
-
Save Keating950/1f6adf79cfa483233f82aef210e36051 to your computer and use it in GitHub Desktop.
python function for debugging from https://andyljones.com/posts/post-mortem-plotting.html
This file contains 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
def extract(): | |
"""Copies the caller's environment up to your IPython session""" | |
import inspect | |
import ctypes | |
frames = inspect.stack() | |
caller = frames[1].frame | |
name, ls, gs = caller.f_code.co_name, caller.f_locals, caller.f_globals | |
ipython = [f for f in inspect.stack() if f.filename.startswith('<ipython-input')][-1].frame | |
ipython.f_locals.update({k: v for k, v in gs.items() if k[:2] != '__'}) | |
ipython.f_locals.update({k: v for k, v in ls.items() if k[:2] != '__'}) | |
ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(ipython), ctypes.c_int(0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment