|
justind
justind at ussonet.net
Thu Aug 10 15:08:38 EDT 2006
It feels like I'm missing either one configuration option or this may
not even be possible.
I have this little bit of code. I expected, that every 4 seconds that x
would increment by 1 on the returned page. It does. However I think that
this same code is loaded into each child process (correct me if I'm
wrong) of apache.
Depending on which child I get, and when they were launched (hitting
refresh rapidly on Firefox seems to demonstrate this too me) I get a
different page back. One will show 4 then a refresh will show 3, another
will show 3, another will show 4 and so on and so forth.
I guess my question is, how can I share the global variable of x among
all the apache child processes, or is this really my problem)?
Any help would be very appreciated.
Code follows below:
from mod_python import apache
import time
import thread
x = 1
def handler(req):
global x
req.content_type = 'text/plain'
req.write("Hello World! " + str(x))
return apache.OK
def do_me():
global x
while True:
time.sleep(4)
x += 1
thread.start_new(do_me,())
|