[mod_python] How to initialize a variable using PythonImport and access it from a Handler?

Graham Dumpleton grahamd at dscpl.com.au
Mon May 2 18:32:52 EDT 2005


For what purpose are you using Twisted? Are you starting up an
instance of the Twisted event system in a separate thread from
the PythonImport?

The only thing I can think of is that what ever you are doing is
blocking for some reason waiting for something that Twisted
is trying to finish, but that perhaps Twisted is itself blocked and
only getting unblocked when the process receives a signal at
shutdown, thus allowing your request handler to actually finish.

How are you handling thread locking and communication of
data between your request handler and Twisted? I am presuming
that since you are possibly creating a Twisted event system
loop as separate thread from PythonImport that you aren't
registering a server cleanup method to properly shutdown
Twisted on Apache shutdown. This would mean that Apache
ends up always having to forcibly kill off Apache subprocesses
because Twisted thread isn't going to die properly.

Anyway, put debug in your request handler which logs to
req.log_error() so as to see if the request handler is blocking
in your call to get the cached results, or somehow later on.

BTW, I know of another framework which can be integrated with
mod_python and allows communications to backend systems using
messaging with request/reply and publish/subscribe mechanism
and has its own event system as well, if you are interested. :-)

Graham

jarrod roberson wrote ..
> thanks that PythonInterpreter directive did it, I can access the object
> and 
> call methods on it but they never return any data until you stop the server
> then it flushes the data out to the browser.
> 
> can you see any reason that the following code might hang like that and
> never return?
> 
> from mod_python import apache
> 
> from myapp import cac
> from twisted.names import dns
> 
> def handler(req):
> req.content_type = "text/plain"
> for answer in cac.getCachedResults(None, None, None):
> req.write(str(answer))
> req.write('\r\n')
> return apache.OK


More information about the Mod_python mailing list