-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support local variables (tb.tb_frame.f_locals) #41
Comments
|
I understand. An easy solution might be to just assign all unpickleable or otherwise problematic |
Btw, previous code and discussion on exactly what you asked: #6 - I guess you could try it and report if it works in your IDE? |
@ionelmc Do you think we could do the following: we could only pickle simple objects (say, primitives and The problem is: gevent uses tblib to save exceptions when they are thrown in another thread to get rid of locals, but pytest uses f_locals for traceback. This means that gevent and pytest don't work together. Pickling primitives shouldn't increase refcount or affect performance badly but will make debugging waaay easier. |
The changes in #59 made by @marcoffee seem fine to me (some tests needed tho, and some docs explaining that repr will be used, and it can create side-effects). Would those changes solve this/the problems on gevent? I'm not a big gevent user. |
Am trying to use tblib to pickle tracebacks in an application with spotty internet so I can later send to Sentry via sentry_sdk.capture_exception() in a retry process. Currently all the local variables are absent and this feature would be really handy even if it only supported primitives. Is there anything other than docs and tests blocking #59? |
So what I would like to have here is some sort of parametrization in tblib.pickle_support's pickle_traceback and install. I think that ideally install would take an option/hook to customize the locals attribute (so the user decides what ends up in locals via his hook). Then I won't need to have a hack in tblib for some pytest thingy or whatever. Eg: from tblib import pickling_support
def pytest_locals(frame):
if "__tracebackhide__" in frame.f_locals:
return {"__tracebackhide__": bool(frame.f_locals["__tracebackhide__"])}
else:
return {}
pickling_support.install(pickle_locals=pytest_locals) |
Yes, this proposal sounds great. |
For your use-case it's going to be roughly like: from tblib import pickling_support
def get_pytest_locals(frame):
if frame.f_locals.get("__tracebackhide__"):
return {"__tracebackhide__": True}
else:
return {}
pickling_support.install(get_locals=get_pytest_locals) |
Thanks! |
Released 3.0 |
tblib 3.0 has been released with support for pickling frame locals: ionelmc/python-tblib#41 With this PR, pytes-pyodide attempts to use the new tblib 3.0 feature, with a fallback for older Pyodide versions.
I'm sure there's a reason for this, but it seems that Traceback objects don't copy the
f_locals
dictionary from the traceback frame. It would be nice to have this so that, for instance, reraised exceptions can be better introspected in an IDE.For instance:
There might be something obvious here that I'm missing?
The text was updated successfully, but these errors were encountered: