reload 
Author Message
 reload

What would happen if a module tried reloading itself?

#

if check_updates(address):
   get_updates(address)
   reload(this_module)

where would the execution flow proceed after that? I'm trying to make a
self updating library...



Mon, 02 Sep 2002 03:00:00 GMT  
 reload

Quote:

>What would happen if a module tried reloading itself?

>if check_updates(address):
>   get_updates(address)
>   reload(this_module)

Before a module can reload itself, it must import itself (to associate
"this_module" with a reference to the module object in the current
namespace), or you must refer to sys.modules["this_module"].

Quote:
>where would the execution flow proceed after that? I'm trying to make a
>self updating library...

The code object which contains the code of the current function/method
is unaffected by the reload(), so the old code will be in effect until
the current function/method returns. OTOH, since name lookups are
dynamic in python, every function call after the reload() will
find the new code.

BUT: This will not work for method calls, because class instances
have a reference to the old class object, which in turn has
references to the old methods' code objects, i.e. the old code
will stay alive as long as there are instances alive that reference
it. New instances will use the reloaded code, though.
If you need dynamic reload of classes to have an effect on
exisiting instances, you will either have to patch the reference to
the new (reloaded) class into the existing instances (set the
__class__ attribute of the instance), or patch the  new methods into the
old class object (modify the __dict__ attribute of the class object).
It's not easy, but possible.

Johannes



Mon, 02 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. URLPresenter reload page

2. Controlling which image reloads....

3. Reloading packages?

4. Dynamical class reload in Java

5. QBE not reloading saved queries

6. Minimized Browses/Forms to show again when app is reloaded

7. ActiveX control can not be loaded after reload the vi

8. DNS reload

9. can't reload nidaq

10. GUI class reloading testrunner for TestUnit?

11. Reloading files

12. Browser crash after I reload my applet...

 

 
Powered by phpBB® Forum Software