On 13 September 2011 10:39, Emyr James <[email protected]> wrote:
> Hi Graham, > Thanks for the reply. > > Just having threads=n with no process value (i.e. all in same process) > seems to be the thing I'm after. So my minimal app with some thread locking > around the increment should be robust. > > I'm still flummoxed by the counter reset after processing 50 requests > though. I put the value 75 in to see if resetting at 50 was some kind of > default. Even with the maximum-requests set to 75, it still resets after 50 > requests. This must be something from apache itself rather than mod_wsgi ? > Yes it's apache. I thought I had it set up for threads but it's prefork. Time to recompile..... :-) > > Regards, > Emyr > > > On 13 September 2011 02:25, Graham Dumpleton > <[email protected]>wrote: > >> Start by reading: >> >> http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading >> >> It talks about global data sharing. >> >> Don't use maximum-requests option it is generally a bad idea and >> should only be used in certain circumstances. What makes you think you >> should be using it? >> >> Overall, if you are new to web programming, unless you have a good >> reason, trying starting with an existing framework such as Flask or >> Django. >> >> Graham >> >> On 12 September 2011 09:13, Emyr James <[email protected]> wrote: >> > 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. >> > >> > >> >> -- >> 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. >> >> > -- 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.
