[mod_python] Multiple processes/threads and dbms

Nick nick at dd.revealed.net
Wed Jun 15 22:23:46 EDT 2005


Dan Eloff wrote:
> But here's the problem. Some resources (files, dbms) are shared
> between processes and threads, so how can you synchronize access to
> them?
> 
> In the Session module which has a session implementation using a dbm,
> _apache._global_lock and _apache._global_unlock is used.

I tend to stay away from using apache's locks, since they are limited in 
number and are used by apache and its modules.  I find flock works well 
in these cases, as it is the usual way to deal with simultaneous access 
to a dbm file from different processes.

As an alternative, if you're only dealing with 1 server process (e.g. 
apache2 on windows), python's threading module does a good enough job 
(Lock/RLock objects).  I find python's native locking mechanisms 
adequate for protecting the critical areas of my code across threads in 
apache.

Nick


More information about the Mod_python mailing list