[mod_python] Import error on multiple interpreters

Tom Wells drshade at gmail.com
Mon Feb 4 11:09:06 EST 2008


Hi Everyone

I have been bumbling along with mod_python for about a month using
mod_python as the apache hooks for integrating into a larger single-sign-on
solution, so far so good. However I'm hitting my head against a weird issue,
and can't seem to find any reference to related issues on this list, nor the
FAQ, so here goes:

I'm supporting multiple apache virtual hosts, and separating them by running
each in a different python interpretor (using PythonInterpreter <site_name>
within the VirtualHost configuration for each site.

I hook into apache via PythonAuthenHandler and PythonAuthzHandler (as my app
is only concerned with authentication and authorization) and make web
service calls using ZSI and some cryptographic routines using ncrypt (Python
OpenSSL wrapper) before allowing or disallowing access to the particular
resource.

So the above works nicely, but while testing I occasionally get the
following error (not on startup, but after a few requests):
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/ssofilter.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/webserver.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/cache.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/authserver.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/ausService_services.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/ausService_services_types.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/utils.py'
[Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429,
interpreter='ssofilter_interpreter_mobile'): Importing module
'/home/tom/dev/auth/ssofilter-apache-2.2/cryptography.py'
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] mod_python
(pid=26429, interpreter='ssofilter_interpreter_mobile',
phase='PythonAuthenHandler', handler='ssofilter'): Application error
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] ServerName: '
mobile.domain.co.za'
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] DocumentRoot:
'/home/tom/dev/auth/mobileweb'
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] URI: '/'
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Location: '/'
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Directory: None
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Filename:
'/home/tom/dev/auth/mobileweb/'
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] PathInfo: ''
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Traceback (most
recent call last):
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in
HandlerDispatch\n    default=default_handler, arg=req, ilent=hlist.silent)
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1202, in
_process_target\n    module = import_module(module_name, path=path)
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 296, in
import_module\n    log, import_path)
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 680, in
import_module\n    execfile(file, module.__dict__)
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/home/tom/dev/auth/ssofilter-apache-2.2/ssofilter.py", line 10, in
<module>\n    cryptography = apache.import_module('cryptography')
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 296, in
import_module\n    log, import_path)
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 680, in
import_module\n    execfile(file, module.__dict__)
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/home/tom/dev/auth/ssofilter-apache-2.2/cryptography.py", line 4, in
<module>\n    cipher = apache.import_module('ncrypt.cipher')
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304, in
import_module\n    return __import__(module_name, {}, {}, ['*'])
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42]   File
"/var/lib/python-support/python2.5/ncrypt/cipher.py", line 1, in
<module>\n    from _ncrypt.cipher import *
[Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] ImportError: No
module named cipher

Now you may think I'm posting this to the wrong list looking at the
stacktrace, but I'm convinced it's mod_python related. While testing the
first few requests go through fine (and ncrypt is imported correctly), but
it seems like the error occurs when apache has decided to create a new
thread (or spawn a new process, difficult to tell) that the error occurs
(the log entries containing "Importing Module" are spat out by mod_python,
as I use the apache.import_module() function for performing all my imports).

A hint is if I make all my sites run under one single python interpreter (by
giving them the same name) I don't experience the problem, but I'd prefer
not to run under this configuration as I'd need to do a whole lot more work
to ensure that data remains separated per site.

Any comments, suggestions would be greatly appreciated!

Thanks,
Tom

PS> Running mod_python 3.3.1-2, running on ubuntu 7.10 in apache
2.2.4-3build1. My apache runtime configuration looks something like:
[Mon Feb 04 17:40:10 2008] [notice] Apache Configuration:
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MAX_DAEMON_USED     -> 2 [Max #
of daemons used so far]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_IS_THREADED         -> 1
[0=Unsupported, 1=Static, 2=Dynamic]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_IS_FORKED           -> 2
[0=Unsupported, 1=Static, 2=Dynamic]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_HARD_LIMIT_DAEMONS  -> 16 [The
compiled max # daemons]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_HARD_LIMIT_THREADS  -> 64 [The
compiled max # threads]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MAX_THREADS         -> 25 [# of
threads/child by config]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MIN_SPARE_DAEMONS   -> 0 [Min #
of spare daemons]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MIN_SPARE_THREADS   -> 25 [Min
# of spare threads]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MAX_SPARE_DAEMONS   -> 0 [Max #
of spare daemons]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MAX_SPARE_THREADS   -> 75 [Max
# of spare threads]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MAX_REQUESTS_DAEMON -> 10 [Max
# of requests per daemon]
[Mon Feb 04 17:40:10 2008] [notice]  AP_MPMQ_MAX_DAEMONS         -> 6 [Max #
of daemons by config]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20080204/7a183054/attachment-0001.html


More information about the Mod_python mailing list