[mod_python] Custom handler thread safety

Graham Dumpleton grahamd at dscpl.com.au
Thu Feb 3 17:30:41 EST 2005

There are bugs in mod_python if using threaded MPM. See:


This may in part contribute to your problems.

Original discussion about it is in mailing list archive. See:


There are emails about the second part of the bug as well, but can't
spot them right now.

There are also various gotchas when using autoreloading that may also
be affecting you.

Look at the patches as a starting point and then we can perhaps go
step by step through some of your issues and how you are implementing
your code.


Huzaifa Tapal wrote ..
> Hello All,
> I wrote a custom mod_python handler that kind of mimicks the cgihandler
> but
> really is an extension to a web framework we have in house.  Just to be
> safe, I implemented thread locking into the handler before any request
> is
> processed.  The application is running on a debian box running Apache 2
> multithreaded with mod_python 3.13.  We are gaining huge performance
> increases by caching our template objects and db connection objects.
> The problem I am running into is that if I run through the application,
> each
> request takes on average 300 ms to process.  However, when we benchmark
> with
> 20 concurrent users, the average goes up to around 2200 ms.  I am very
> sure
> that this is due to a thread locking shared objects in memory which results
> in another thread waiting for the lock to be released.
> If I take the thread locking mechanism out then we run into problems with
> there being too many connections being made to the MySQL db if the cached
> connection is being used and then the db starts dropping connections.
> Any help would be much appreciated.  Even if there are any other good
> handlers out there other than cgihandler and publisher.
> Hozi

More information about the Mod_python mailing list