Python: sys.exc_info() is missing local variables
In Python, I have code that catches an exception, like this:
try:
<do stuff>
except:
exc_info = sys.exc_info()
The problem I'm running into is that the traceback object (exc_info[2]) is non-deterministically missing local variables in the traceback objects. I know this for a fact because I run the exact same code and sometim开发者_高级运维es the variables are in tb.tb_frame.f_locals and sometimes not. The global variables are always correct in tb.tb_frame.f_globals.
What is populating the f_locals structure? What might cause that local variables dictionary to be empty sometimes?
What is in the locals is completely dependent on the code in that local context. For example:
if condition:
foo='foo'
else:
bar='bar'
if condition==True
then foo
will be in locals()
and bar
will not, otherwise bar
will be in locals()
and foo
will not.
精彩评论