reloading updated modules in long running server?

Lee Harr missive at frontiernet.net
Fri Oct 15 22:08:35 CEST 2004


On 2004-10-15, <exarkun at divmod.com> <exarkun at divmod.com> wrote:
> On Fri, 15 Oct 2004 10:36:40 -0700, aurora <aurora00 at gmail.com> wrote:
>>I am looking for a way for reloading updated modules in a long running  
>> server. I'm not too concerned about cascaded reload or objects already  
>> created. Just need to reload module xxx if the corresponding xxx.py is  
>> updated.
>> 
>> I found something useful in module.__file__. Would it work if I use it to  
>> generate filenames xxx.py xxx.pyc and then compare their mtime? I'm not  
>> too sure about the mechanism of generation of .pyc file. Would it be too  
>> system specific to reply on?
>
>   Is it really important that they be reloaded automatically as soon as 
they change?  What if several modules are being updated in concert, and 
the change is noticed before all of the files have been updated?  
Won't the source be in an inconsistent state and probably take down, 
or at least effect negatively, the server?
>
>   I would put a big fat (possibly figurative) button on the application 
somewhere and press it when I wanted the source updated.
>
>   Jp


That is just what I do while developing my twisted/ nevow app.

I have a button which calls:


from twisted.python.rebuild import rebuild
from nevow import rend

class CommonPage(rend.Page):
    def child_rebuild(self, request):
        if testing:
            import pages
            rebuild(pages)
            rebuild(cdb)
            return self


pages is the module in which this class lives, and
cdb is the database connector and methods.

I have never had any problems with it, but I probably am not
pushing the envelope too much.




More information about the Python-list mailing list