I have a server using apache2 with mod_python that seems to reset global variables after some short period of time. Until this happens, all the features of the server and global variables are handled exactly as I would expect.
To rule out the possibility of some runtime error (although I do have debugging on and don't see any errors), I made this simplified script to demonstrate how a global variable is being reset. It just holds a global counter and increments it every time the server is accessed:
from mod_python import apache
counter = 0
def handler(req):
global counter
counter += 1
req.content_type = 'text/plain'
req.write('counter: '+str(counter))
return apache.OK
I can keep refreshing the page and watch the counter go up as expected. However, at some point the counter jumps back to 1.
I tried simply holding the F5 key down to rapidly refresh the page and see if it would still reset while I was continually accessing it, and I noticed something else. At first it would still drop down to 1 a few times, but eventually it would drop down to other numbers. For example I got up to around 200 refreshes and it just dropped down to around 100, and would occasionally even jump upward back into the 200s.
It seems like there are multiple virtual shells for the server script being started, and the server just randomly switches between them or starts new ones. How can I prevent this?