[mod_python] Apache on Windows and concurrency

Iain Mackay imm at iain-mackay.org
Tue Jul 6 21:17:45 EDT 2004

Thanks Grisha for being so quickly on the case.

Session.py also includes the solution to my problem, using the Apache global

I now have the following code to protect a section of  script that is using
the database connection (it uses SQLite but would apply mutatis mutandis to
another database). I have restored multi-threading and all works smoothly. 

If this is the best way to do this, it might be worth a mention in the next
release of the documentation. I suppose ideally application code shouldn't
use _apache.

from mod_python import apache

import _apache

import re

import sqlite

import userdatabase

import sys


users = None

apache.log_error ("userHandler initialising", apache.APLOG_INFO)


def beginDB (req):

        _apache._global_lock(req.server, None, 0)

            global users

            if not users:



                                                defaultUser =
req.get_options ()["defaultUser"]


                                                defaultUser = "guest"

                                    users = userdatabase.UserDatabase\

(req.get_options ()["dbFile"],

                                                077, autocommit=1),


                                    (type, value, tb) = sys.exc_info()

                                    apache.log_error ("Cannot access user
database: %s (%s)" % (type, value),



def endDB (req):

        _apache._global_unlock(req.server, None, 0)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://modpython.org/pipermail/mod_python/attachments/20040706/04fb22db/attachment.html

More information about the Mod_python mailing list