Warning: mod_python, Python, and threads

0 views
Skip to first unread message

Robert Brewer

unread,
Feb 10, 2006, 5:21:05 PM2/10/06
to cherryp...@googlegroups.com, turbo...@googlegroups.com
http://sourceforge.net/tracker/index.php?func=detail&aid=1163563&group_i
d=5470&atid=105470

The above Sourceforge ticket describes a problem that occurs when using
Python 2.3.5 or 2.4.1 with subinterpreters (as used in mod_python) when
spawning new threads. If you use this combination, you should probably
upgrade immediately to Python 2.4.2 (or downgrade to 2.3.4).

In my case, I have a CherryPy app which spawns new threads to deal with
scheduled tasks (like cache sweepers and email reminders) that occur
outside any HTTP request thread. This worked fine until I upgraded my
dev machine to Python 2.3.5 and my production/staging machines to 2.4.2,
at which point the Thread and Timer objects were being created
successfully, but would not actually execute their target functions.

This is particularly dangerous for two reasons:

1. No errors are raised by the failure. Threads are simply not called
at the appropriate time. It took me six months to get enough of a user
report on this to start investigating it (although this is our "off
season").
2. My application tests did not catch the failure, because they skip
starting up Apache, using CherryPy's builtin WSGI server instead. All
the tests passed, because the threads were not restricted (under test)
as they were when running in a subinterpreter (in production).


Hoping-this-saves-someone-else-hours-of-frustration,

Robert Brewer
System Architect
Amor Ministries
fuma...@amor.org

Reply all
Reply to author
Forward
0 new messages