Repository navigation
Description
I've noticed that often when I make a mistake in my python code that would raise an error, that 'raise' in turn raises another error from ipython. E.g., I recently tried placing a legend on a plot in matplotlib with the line
leg = plot_ax.legend(loc='best', framealpha=1.0, fontsize=12, fontfamily='Source Sans Pro')
The error here is that fontfamily is not a valid keyword argument to legend. So it raised an error, as it should. However, that in turn triggered something else:
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
File "/Users/sbasu1/packages/python3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-6-a9612f85a127>", line 1, in <module>
caf.Comparison_plot('total', freq='monthly')
File "/Users/sbasu1/Code/OCO2/LMT_Project/check_mass_balance.py", line 122, in Comparison_plot
leg = plot_ax.legend(loc='best', framealpha=1.0, fontsize=12, fontfamily='Source Sans Pro')
File "/Users/sbasu1/packages/python3/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 406, in legend
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'fontfamily'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sbasu1/packages/python3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2040, in showtraceback
stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sbasu1/packages/python3/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1101, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "/Users/sbasu1/packages/python3/lib/python3.8/site-packages/IPython/core/ultratb.py", line 319, in wrapped
return f(*args, **kwargs)
File "/Users/sbasu1/packages/python3/lib/python3.8/site-packages/IPython/core/ultratb.py", line 353, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "/Users/sbasu1/packages/python3/lib/python3.8/inspect.py", line 1503, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
File "/Users/sbasu1/packages/python3/lib/python3.8/inspect.py", line 1461, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "/Users/sbasu1/packages/python3/lib/python3.8/inspect.py", line 708, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "/Users/sbasu1/packages/python3/lib/python3.8/inspect.py", line 754, in getmodule
os.path.realpath(f)] = module.__name__
AttributeError: module has no attribute '__name__'
---------------------------------------------------------------------------
It's the second error that concerns me, AttributeError: 'TypeError' object has no attribute '_render_traceback_'. It has nothing to do with my faulty code, seems to be an internal ipython problem, and obfuscates the error I should care about (wrong keyword in my code).
What is causing this and how can I fix it? I'm using ipython 7.9.0 on python 3.8.0.
Thanks,
Sourish
Activity
Carreau commentedon Nov 12, 2019
That is super strange; can you share a full session that trigger the bug ? Do you have customization ?
I cannot reproduce on 3.7;
And some of the exceptions you see should be caught:
I'll try on 3.8 maybe something changed in it ?
AgilentGCMS commentedon Nov 13, 2019
I'll see if I can reproduce it in a few lines. It happens occasionally, which is the worst type of bug :-(
Carreau commentedon Nov 13, 2019
Ok, so I can "force" the error:
I"m just curous about what type of module could not have
__name__any change you use multiprocessing ?AgilentGCMS commentedon Nov 13, 2019
I don't have multiprocessing. The only customization I have is that in
.ipython/profile_default/startup/00-load_modules.pyI load the following modules:In trying to reproduce this second exception, I realized that the same erroneous line of code doesn't always trigger it. E.g., right now one of my scripts triggered this error:
The line in
/Users/sbasu1/Code/OCO2/LMT_Project/analyze_spread.pythat triggered the first error had a typo (my bad), since indeedxco2_std_smodelis not defined within the script,xco2_std_xmodelis. However, if I cut and paste that offending line in a fresh ipython console, where none of the names is defined, I get instead:i.e., a standard
NameError, not the added exception.Carreau commentedon Nov 16, 2019
If you see the error; can you run the following ?
That might shed light on what actually has no
__name__.AgilentGCMS commentedon Nov 17, 2019
So, the error happened again, again due to a typo. Here's the output from your code block:
That script
analyze_spread.pyis the actual script I'm running.Fix the issue with %run-ing something with multiprocessing
Carreau commentedon Nov 22, 2019
Can you try #11959 ?
Carreau commentedon Nov 24, 2019
closed by #11959