[IPython-user] Problem with IPShellEmbed

Michael Foord mike at pcblokes.com
Fri Jan 28 05:31:26 CST 2005


Fernando Perez wrote:

> 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:
>
Thanks Fernando.
I'll check this out tonight, but won't be able to email the results 
until Monday I don't think. I do wonder if psyco is somehow involved. 
it's not explicitly imported in my code, but maybe in one of the files 
that is being run.

Anyway - I'll try your suggestion. thanks.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

>     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