reloading updated modules in long running server?

Pierre Quentel quentel.pierre at
Sat Oct 16 11:17:31 CEST 2004

I don't know if there is a way to catch the event "a file has been 
modified in the file system" but you can always check if something has 
changed in sys.modules every time a request is processed by the server, 
or every n second

Something like this should work :

for m in sys.modules.values():
     if m and hasattr(m,"__file__"):
         if updateTime.has_key(m):
             if modTime != updateTime[m]:


aurora a écrit :
> 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 is  
> updated.
> I found something useful in module.__file__. Would it work if I use it 
> to  generate filenames 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?

More information about the Python-list mailing list