[mod_python] Thread safety

Graham Dumpleton grahamd at dscpl.com.au
Tue Jun 7 19:06:52 EDT 2005


On 07/06/2005, at 6:42 AM, Dan Eloff wrote:

> When using a request handler, mod_python calls handler(req) for every
> incoming request. I would say it's a safe guess that this implies that
> handler can be called concurrently in different threads and anything
> done in this function and any functions it calls must be thread safe.
> I didn't find any mention of this in the docs (I didn't look too
> hard), so I thought I'd verify with the people sure to know.

BTW, you might want to read this old posting to the mailing list.

   http://www.modpython.org/pipermail/mod_python/2004-October/016605.html

Using threading and having automatic module reloading enabled at the
same time can be quite dangerous. Most of the problems arise because
of how apache.import_module() is implemented so as to use standard
Python module importing mechanisms and storage of modules in 
sys.modules.

Some of these problems are eliminated by systems such as Vampire and
mpservlets which have their own module loading mechanism which does
not reload on top of an existing module. Vampire goes a bit further
than mpservlets in as much as Vampire provides a means of still 
preserving
data across module reloads under strict user control so that thread
locking issues can be addressed.

Note, I posted this a fair time ago and I hope it is still accurate. I
understand things a bit better now and so possibly I may know of
simpler ways around the problems. :-)


Graham



More information about the Mod_python mailing list