[SciPy-user] Ipython "run"

Fernando Perez Fernando.Perez at colorado.edu
Fri Jul 29 11:03:16 CDT 2005


Ryan Krauss wrote:
> If you only want to reload one or two modules that you are developing, 
> you can try two approaches.  One is to use the %macro command   to 
> combined reload with run.  The other is to hard code into your scripts 
> to reload modules that you are developing after you have imported them.
> 
> Fernando may have better advice.

Not really: what you describe is pretty much what I always do.  Many of my 
'top-level' scripts which use modules I'm in the middle of modifying, look like:

import foo
reload(foo)
foo.dostuff()

It's not terribly elegant, but it works.  And as John said, wholesale 
reloading of everything can be very expensive, so it's not a good idea as a 
default.

Having said that, I should mention dreload(), part of ipython.  It _tries_ to 
do a recursive ('deep') reload of a given module, and I know many ipython 
users love it.

Given that there is no way for any tool to guess, out of the many modules in 
memory, which ones the user actually _wants_ reloaded, I think the manual 
solution is not all that bad.

I should finally add that extension modules can NOT be reoloaded, to the best 
of my knowledge.  I just checked what Idle does: it runs the user's code in a 
separate process altogether:

fperez   10662  1.4  0.9 15192 9936 pts/15   S+   09:54   0:00 /usr/bin/python 
/usr/bin/idle
fperez   10673  1.0  0.5 13884 5360 pts/15   Sl+  09:55   0:00 /usr/bin/python 
-c __import__('idlelib.run').run.main(True) 8833

And after hitting F5:

fperez   10662  0.9  0.9 15192 9936 pts/15   S+   09:54   0:00 /usr/bin/python 
/usr/bin/idle
fperez   10691  1.6  0.5 13884 5360 pts/15   Sl+  09:55   0:00 /usr/bin/python 
-c __import__('idlelib.run').run.main(True) 8833

Notice the process number for the user code execution has just changed.

In summary, Idle's F5 is equivalent to John's solution, to use !python foo.py. 
   Unfortunately because this runs in a separate process, you lose nice 
exception tracebacks, integrated debugging, etc.  It would not be impossible 
to write a little magic that does something similar for ipython, while 
retaining the settings for exceptions, pdb and other things.  I'll keep it in 
mind for a future release, unless somebody beats me to it.

Cheers,

f



More information about the SciPy-user mailing list