[IPython-user] Problem with IPShellEmbed
Fernando Perez
Fernando.Perez at colorado.edu
Fri Jan 28 04:24:44 CST 2005
Michael Foord wrote:
> I've encountered a problem with IPShellEmbed, for my Movable Python
> project. It's quite likely that this problem is my fault - but I would
> still appreciate help ! It looks like a frame object is expected and
> None is returned.
>
> Basically *sometimes* a call to IPShellEmbed will fail :
>
> ipshell = IPShellEmbed(argv, banner=banner)
>
> The error raised occurs in :
> File "C:\Python24\Lib\site-packages\IPython\Itpl.py", line 182, in __str__
> while frame.f_globals["__name__"] == __name__: frame = frame.f_back
> AttributeError: 'NoneType' object has no attribute 'f_globals'
Very, very strange. It seems like you have a stack with a bogus frame
somewhere. Here's something to try: in the Itpl.py file, around line 182,
comment out 3 lines and add a _getframe as follows:
def __str__(self):
"""Evaluate and substitute the appropriate parts of the string."""
## try: 1/0
## except: frame = sys.exc_traceback.tb_frame
## while frame.f_globals["__name__"] == __name__: frame = frame.f_back
frame = sys._getframe(1) ##### <<<--- NEW LINE HERE
loc, glob = frame.f_locals, frame.f_globals
This should pull the caller's frame correctly. Itpl was originally written
before sys._getframe existed, so it used the 1/0 trick. If this fixes your
problem, I'll add it for the next release.
Let me know what happens.
Cheers,
f
More information about the IPython-user
mailing list