a newbie's question

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Mar 11 14:10:40 CET 2010


PEYMAN ASKARI wrote:
> Hello
>
> I need some help dynamically reloading modules. As it turns out, it is 
> not as simple as calling reload, as outlined here
> http://pyunit.sourceforge.net/notes/reloading.html
>
> Is there builtin support for this? The example they gave does not seem 
> to work for me, and I am unclear as to what PyUnit is.
>
> Thanks
>
>
> Peyman
>

Please don't top post.
As for your question, there's no built-in method to reload a module 
because it is not possible (in a generic manner).

However if you *really* want to do it you can do it for your particular 
module (and only for this one).
It is tough to explain though. You have to know perfectly the python 
object model and I'm not familiar enough with it to do the explanation.

So:

1/ try to live without dynamic reload
2/ if you *really* require dynamic reload, you can try to execute the 
module in a subprocess. That way, every time you start a new subprocess, 
the last up to date version of the module is used
3/ reload the module and all it's related objects currently in memory, 
this is painfull and there are many traps to fall into. I'll let someone 
else answer this point.

JM



More information about the Python-list mailing list