Ticket #197 (closed defect: fixed)

Opened 1 year ago

Last modified 11 months ago

%run doesn't doesn't update from file correctly with use of IPShellEmbed

Reported by: quadri@strw.leidenuniv.nl Assigned to: vivainio
Priority: high Milestone:
Component: ipython Version:
Severity: normal Keywords:
Cc:

Description

I was testing some code using %run, then I would modify the code, and run it again, but the new output wouldn't reflect the changes that I'd made. It appears that the problem is the way that I'm using IPShellEmbed. Here is a simple example of the problem, making use of a file called test.py:

In [1]: cat test.py
x=3
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()

def func():
    return x

In [2]: %run test
In [3]: x
Out[3]: 3
In [4]: func()
Out[4]: 3
############ now edit the file so that x=4 ##############
In [5]: %run test
In [6]: x
Out[6]: 3
In [7]: func()
Out[7]: 3

However, if I comment out the line "ipshell = IPShellEmbed()" in test.py, restart ipython, and repeat the procedure shown above, then last few input/output look like this (which I believe is the correct behavior):

############ now edit the file so that x=4 ##############
In [5]: %run test
In [6]: x
Out[6]: 4
In [7]: func()
Out[7]: 4

As far as I can tell the problem is specific to IPShellEmbed(), since it doesn't seem to occur when aliasing other functions. Also, it doesn't seem to matter if x is declared inside of func(), or if the import command occurs inside of func().

I'm using ipython 0.8.1, python 2.5.1, Mac OS 10.4.10 on a PPC.

Change History

12/30/07 15:26:25 changed by vivainio

Yeah, it seems instantiation of ipshellembed leaves all the names pointing to the old objects (new bindings are ineffective).

12/30/07 15:36:14 changed by vivainio

  • status changed from new to assigned.
  • owner changed from fperez to vivainio.

12/30/07 15:51:23 changed by vivainio

It seems that instantiation of ipshellembed inside %run screws up IPython pretty badly in general. If you print self.shell here (in Magic.py / run):

                   # update IPython interactive namespace
                    del prog_ns['__name__']
                    print "prog_ns",prog_ns
                    print self.shell
                    self.shell.user_ns.update(prog_ns)

You'll see that InteractiveShell? instance is different on every run if you instantiate ipshellembed. Also, prog_ns is polluted by lots of IPython crap.

12/30/07 16:42:58 changed by vivainio

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed by r2910