reimport module every n seconds

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Feb 17 16:33:59 CET 2011


Santiago Caracol wrote:
> Hello,
>
> a server program of mine uses data which are compiled to a Python
> module for efficiency reasons. In some module of the server program I
> import the data:
>
> from data import data
>
> As the data often changes, I would like to reimport it every n (e.g.
> 10) seconds.
>
> Unfortunately, it is rather difficult and probably not a good idea to
> manipulate the main function of the server program, as it comes from
> Django. (Already asked in the Django newsgroup, but I got no answer
> there.) Is there a way to do the reimport in a module that is used by
> the main program?
>
> Santiago
>   
import data

def getUpdate():
    reload(data)
    return data.data

JM

WARNING : there's a lot to know about reload, the main thing is that it 
cannot properly reimport a module in a sense that all objects already 
created from that module are not impacted. You can search this archive 
if you want to know more as this subject has already been discussed many 
times.



More information about the Python-list mailing list