Alan Kennedy
modpython at xhaus.com
Fri Jan 25 09:35:06 EST 2002
Greetings All, I'm putting together a session tracking mechanism for Apache and mod_python, on Win and Linux. And my mind is being twisted trying to decide if I need to worry about thread safety or not. My confusion arises from trying to juggle the concepts of the Python Global Interpreter Lock and the way that Apache handles simultaneous requests. On Windows, Apache spawns a single child, which then creates a thread to service every request received. On Linux, Apache maintains a pool of single-threaded child processes, which compete to service incoming requests. So, imagine I have a mod_python handler function, which is going to extract a session ID from incoming requests, and use that as a key to retrieve a corresponding session object from some storage (say, a memory mapped file, rdbms(?)). That session object can then be modified by the handler function, and thus must then be written back to storage. Since it is possible for two requests from the same session to be handled by different threads windows)/processes(linux), I obviously have a concurrent access problem. On Linux, there are no threading issues, since all of the processes serving requests are single-threaded. However, it is obviously different on multi-threaded Windows. On Windows, I don't know if it is possible for two threads to update the same python object at the same time, i.e. I don't know the effect of the Global Interpreter Lock(GIL). On Windows, the two threads will definitely be run in the same interpreter (the default configuration for mod_python). So, my question: do I need to protect the session objects against concurrent access from multiple threads (and thus complicate the code)? Or can I ignore the issue, i.e. is access to the object serialised by the GIL? I know I could probably answer my question by reading and understanding the python and mod_python source code. But I was hoping someone might be able to give me pointers to documentation which might throw some light on the scenario? Many thanks, Alan. --------------------------------------------- This message was sent using WebMail by CyberGate. http://www.gate.net/webmail
|