[IPython-user] how to use @dreload after a @run?

Fernando Perez fperez at colorado.edu
Sun May 16 23:13:13 CDT 2004


Hi Maciej,

Maciej Kalisiak wrote:
> I test my programs under IPython using @run foo.py.  Occasionally I find a
> bug and correct the source of one of the modules imported by foo.py.  If I
> again do @run foo.py, foo.py source will be reread, but not that off the
> modules it imports.  From what I understand, this is where @dreload comes in.
> My question is, how exactly do I invoke this command???  I haven't seen any
> particular examples anywhere. "@dreload foo" and "@dreload bar" seem to be
> not the correct way (errors).

Unfortunately, it's very non-trivial to get this kind of setup to work 
reliably.  While 'dreload bar' may work in some cases, the problem is getting 
all references to bar replaced.  You may have in foo other modules which (deep 
in a chain) point to bar, and while bar and its dependencies will get 
recursively reloaded, the 'old' bar will still be pointed to by someone.

Frankly, except in cases where I have at most one level of dependencies, I 
have just punted this issue, and simply restart ipython after changing 
something deep in the hierarchy.  If I am editing foo.py, obviously @run will 
reload it, and sometimes I'll just hand-edit a 'reload(bar)' in foo.py while 
I'm testing.  But if the code I'm changing is deeper in the chain, I have 
honestly failed to find a good recipe for ensuring a proper reload.

I'd love to hear from other users, in case someone has found a working system 
for handling this, which is cleaner than my brute-force 'restart ipython' method.

Regards,

Fernando.

PS.  If dreload itself is giving you errors, please post them so that I can 
fix them.  For single-module recursive calls, dreload() at least should work 
(and I know of users who like it a lot).  Just send me a traceback and I'll 
have a look.




More information about the IPython-user mailing list