Hi,
I'm thinking of using wsgi to do a simple framework for some webapps I have in mind. I'm trying to understand how mod_wsgi handles global data and what kind of thread synchronisation I need to contorl access to the global data.

I wrote this very simple app to test global variables...

counter=0
def application(environ, start_response) :
    global counter
    status='200 OK'
    response_headers=[('Content-type', 'text/plain')]
    start_response(status, response_headers)
    counter+=1
    return ['counter is '+str(counter)+'\n']

I had the following in my apache conf...

WSGIDaemonProcess myserver threads=2 maximum-requests=75

So I should have 1 process with 2 threads in it.

When I repeatedly hit the browser, I see the counter go up as expected but then it goes back to 1 after 50 hits. I'm curious how excactly the threads & processes work regarding global variables.

Why does it reset after 50 hits ?
Is it possible to write some kind of thread-id in my output so I know which of the 2 threads it hits? If i have threads recycling after the 75 requests, will that also reset the global variable each time one of the threads hits maximum-request ?...although the global variable seems to be resetting now ...why ? ) I'm guessing that to avoid race conditions I'd need to use the threading module and put a lock around the counter increment...or do the mod_wsgi threads not work like that ? i.e. each daemon thread has it's own self contained python interpreter so no data is shared between the mod_wsgi threads ?

Any answers on the above greatly appreciated.
Regards,
Emyr


--
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to