[IPython-user] Problem with IPShellEmbed
mike at pcblokes.com
Mon Jan 31 09:46:52 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
>> 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
> ## try: 1/0
> ## except: frame = sys.exc_traceback.tb_frame
> ## while frame.f_globals["__name__"] == __name__: frame =
> 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.
Hmm... I've got to the bottom of the problem I had with IPShellEmbed.
When I made the change suggested - (`frame = sys._getframe(1)`) which
didn't stop the crash but revealed a more helpful error message.
Traceback (most recent call last):
File "movpy.py", line 921, in ?
File "movpy.py", line 551, in interactive
File "IPython\Shell.pyo", line 133, in __init__
File "IPython\ipmaker.pyo", line 82, in make_IPython
File "IPython\iplib.pyo", line 602, in __init__
File "IPython\Itpl.pyo", line 227, in itpl
File "IPython\Itpl.pyo", line 184, in __str__
File "psyco\support.pyo", line 120, in __getattr__
AttributeError: local variables of functions run by Psyco cannot be
accessed in any way, sorry
Basically IPython doesn't play nicely with psyco (psyco hides local
variables in functions it's covering).
As an experiment try typing ``import pscyo; psyco.full()`` at an IPython
command line ! (I *do* get the same result in Python 2.3 and Python 2.4)
The difficulty that leaves me with, is that my script (movpy.py) is
running other python scripts before running IPython. This means, if any
of these scripts import psyco - IPython dies. What I need to be able to
do is detect these circumstances and maybe explicitly supply the locals
variables as a dictionary to IPython. I probably also need to be able to
turn psyco off....... (Alternatively I can trap for AttributeError and
run the simpler shell instead..).
More information about the IPython-user