question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support local variables (tb.tb_frame.f_locals)

See original GitHub issue

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:

>>> def func():
...     a = 1
...    print locals()
...     try:
...         raise ValueError()
...     except Exception as e:
...         exc_type, exc_value, exc_tb = sys.exc_info()
>>> exc_tb.tb_frame.f_locals
{'a': 1, e: ValueError()}
>>> tb = Traceback(exc_tb)
>>> tb.as_traceback().tb_frame.f_locals
{}

There might be something obvious here that I’m missing?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ionelmccommented, May 29, 2019

f_locals are a can of worms basically, we’d have lots of corner cases like reference loops, unpickleable stuff, overblown pickle result size and such. I’m not saying no but I’m not a fan of the idea either - the primary goal of this library is to be able to display a traceback using stdlib modules (like traceback) from a different process.

0reactions
ionelmccommented, Aug 26, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting More Information from Tracebacks - Python Cookbook ...
This recipe exploits this structure and the rich amount of information held by frame objects, including the dictionary of local variables for the...
Read more >
Find local variables in the traceback for an exception
f_locals property and so on up to the top of the stack. I wrote this function to find them: def _find_variables(tb, vars): to_find ......
Read more >
Python: sys.exc_info() is missing local variables - Stack Overflow
The problem I'm running into is that the traceback object (exc_info[2]) is non-deterministically missing local variables in the traceback ...
Read more >
Local Variables - Crafting Interpreters
Local variables are one of the most-used parts of a language. If locals are ... They typically use the native stack mechanisms supported...
Read more >
Local variables created in VOPSOP | Forums - SideFX
But i can't access that variable in for eg. extrude sop (with $). ... If that SOP doesn't support local variables (after looking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found