Use a Thread to reload a Module?

Gregory Piñero gregpinero at gmail.com
Fri Dec 22 18:16:51 EST 2006


Hi Python Experts,

I hope I can explain this right.  I'll try.

Background:
I have a module that I leave running in a server role.  It has a
module which has data in it that can change.  So every nth time a
function in the server gets called, I want to reload the module so it
has the freshest data.  But there's a lot of data so it takes 5-10
seconds to do a reload.

My question is:
Would I be able to launch a seperate thread to reload the module while
the server does it work?  Hopefully it would be using the old module
data right up until the thread was finished reloading.

Thanks in advance,

Greg

Here's some psuedo code that might illustrate what I'm talking about:

import lotsa_data

def serve():
    reload(lotsa_data) #can this launch a thread so "do_stuff" runs right away?
    do_stuff(lotsa_data.data)

while 1:
    listen_for_requests()



More information about the Python-list mailing list