[mod_python] Apache on Windows and concurrency

Iain Mackay imm at iain-mackay.org
Thu Jul 8 01:49:59 EDT 2004

Dear Nicolas
Thank you for those most helpful comments. 
As a first step I rewrote my specimen code using a Lock on a global database
connection: This is very much faster than the server locks, and at least
with a modest load seems to have no concurrency problems either.
import threading

users = None
apache.log_error ("userHandler initialising", apache.APLOG_INFO)
DBLock = threading.Lock()

def beginDB (req):
	global DBLock
	global users
	if not users:
				defaultUser = req.get_options
				defaultUser = "guest"
			users = userdatabase.UserDatabase\
				(sqlite.connect (req.get_options
				077, autocommit=1), defaultUser)
			(type, value, tb) = sys.exc_info()
			apache.log_error ("Cannot access user database: %s
(%s)" % (type, value),
def endDB (req):
This is still sharing a single database connection. The issue of how much
benefit you can get from multiple connections is a complex one; in the case
of SQLite I suspect it is quite limited, because SQLite locks the entire
database for each transaction. In a production situation one might well us a
different database.
If we move to a connection-per-thread paradigm, the code becomes slightly
more complex than I like to attempt in the wee small hours, so I'll leave
that for later.
I suppose the main drift here is that on Windows one has to beware threading
issues in mod_python; but t(h)read carefully and all will be well.

More information about the Mod_python mailing list