Skip to content
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

failing traceback in terminal ipython for first exception #2357

Closed
jstenar opened this issue Aug 29, 2012 · 1 comment
Closed

failing traceback in terminal ipython for first exception #2357

jstenar opened this issue Aug 29, 2012 · 1 comment
Milestone

Comments

@jstenar
Copy link
Member

jstenar commented Aug 29, 2012

The minimum example that reliably recreates this problem on windows python 2.7 (master ffc36cc):

Create an empty profile and add the following code to a py file in the startup folder for the new profile:

import inspect
inspect.stack()

Now start ipython and generate an exception:

IPython 0.14.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: empty

In [1]: 1/0
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
  File "C:\python27\lib\site-packages\ipython-0.14.dev-py2.7.egg\IPython\core\ultratb.py", line 749, in structured_traceback
    records = _fixed_getinnerframes(etb, context, tb_offset)
  File "C:\python27\lib\site-packages\ipython-0.14.dev-py2.7.egg\IPython\core\ultratb.py", line 235, in _fixed_getinnerframes
    records  = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\python27\lib\inspect.py", line 1041, in getinnerframes
    framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File "C:\python27\lib\inspect.py", line 1001, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "C:\python27\lib\inspect.py", line 456, in getsourcefile
    if hasattr(getmodule(object, filename), '__loader__'):
  File "C:\python27\lib\inspect.py", line 499, in getmodule
    f = getabsfile(module)
  File "C:\python27\lib\inspect.py", line 468, in getabsfile
    _filename = getsourcefile(object) or getfile(object)
  File "C:\python27\lib\inspect.py", line 447, in getsourcefile
    if string.lower(filename[-4:]) in ('.pyc', '.pyo'):
TypeError: 'NoneType' object is not subscriptable

Unfortunately, your original traceback can not be constructed.

The second time we try to generate the traceback:

In [2]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0

ZeroDivisionError: integer division or modulo by zero

As far as I have been able to determine the traceback is caused by __main__.__file__ being None at startup in the terminal console but not in any of the other terminals. %run:ing some code also sets __main__.__file__ to a reasonable value.

In [1]: %run pass.py

In [2]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0

ZeroDivisionError: integer division or modulo by zero

Setting a break point in inspect.getsourcefile:

In [1]: 1/0
> c:\python27\lib\inspect.py(449)getsourcefile()
-> if string.lower(filename[-4:]) in ('.pyc', '.pyo'):
(Pdb) list 446
441
442     def getsourcefile(object):
443         """Return the filename that can be used to locate an object's source.
444         Return None if no way can be identified to get the source.
445         """
446         filename = getfile(object)
447         if filename is None:
448             import pdb;pdb.set_trace()
449  ->     if string.lower(filename[-4:]) in ('.pyc', '.pyo'):
450             filename = filename[:-4] + '.py'
451         for suffix, mode, kind in imp.get_suffixes():
(Pdb) object.__file__
(Pdb) object
<module '__main__' (built-in)>
@jstenar
Copy link
Member Author

jstenar commented Aug 29, 2012

whoops I managed to create this one twice (closing now)

@jstenar jstenar closed this as completed Aug 29, 2012
@minrk minrk added this to the no action milestone Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants