reloading updated modules in long running server?

Bryan belred1 at yahoo.com
Sat Oct 16 11:07:17 EDT 2004


Pierre Quentel wrote:
> 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 :
> 
> updateTime={}
> for m in sys.modules.values():
>     if m and hasattr(m,"__file__"):
>         modTime=os.path.getmtime(m.__file__)
>         if updateTime.has_key(m):
>             if modTime != updateTime[m]:
>                 reload(m)
>                 updateTime[m]=modTime
>         else:
>             updateTime[m]=modTime
> 
> Pierre
> 

if you have class A in module a.py and class B(A) in module b.py, and in module c.py you instantiale b = B().  will 
there be a problem if you reload module b, then c, then a?  in the previous example, m in sys.modules.values() doesn't 
take this into account.

bryan



More information about the Python-list mailing list