[mod_python] Import error on multiple interpreters

Tom Wells drshade at gmail.com
Tue Feb 5 08:13:53 EST 2008


Hi Graham

I think i've nailed this one down - turns out that the ncrypt package
doesn't like to be loaded twice into the same process (although under
different interpreters). Confirmed this by writing a simple
startup.pyscript which contained the following:

from mod_python import apache
cipher = apache.import_module('ncrypt.cipher')
apache.log_error('******** IMPORTED', apache.APLOG_NOTICE)

Then, in my apache config did a:
PythonImport startup interpreter1
PythonImport startup interpreter2

Running this, I see in my log file:
[Tue Feb 05 14:34:23 2008] [notice] SIGUSR1 received.  Doing graceful
restart
[Tue Feb 05 14:34:23 2008] [notice] mod_python: Creating 8 session mutexes
based on 4 max processes and 25 max threads.
[Tue Feb 05 14:34:23 2008] [notice] mod_python: using mutex_directory /tmp
[Tue Feb 05 14:34:23 2008] [notice] Apache/2.2.4 (Ubuntu) mod_python/3.3.1
Python/2.5.1 configured -- resuming normal operations
[Tue Feb 05 14:34:24 2008] [notice] ******** IMPORTED
[Tue Feb 05 14:34:24 2008] [notice] ******** IMPORTED
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1695,
in ImportDispatch
    module = import_module(module_name, log=debug)
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 296,
in import_module
    log, import_path)
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 680,
in import_module
    execfile(file, module.__dict__)
  File "/home/tom/dev/auth/ssofilter-apache-2.2/startup.py", line 4, in
<module>
    cipher = apache.import_module('ncrypt.cipher')
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304,
in import_module
    return __import__(module_name, {}, {}, ['*'])
  File "/var/lib/python-support/python2.5/ncrypt/cipher.py", line 1, in
<module>
    from _ncrypt.cipher import *
ImportError: No module named cipher
[Tue Feb 05 14:34:25 2008] [error] directive_PythonImport: error importing
startup
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1695,
in ImportDispatch
    module = import_module(module_name, log=debug)
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 296,
in import_module
    log, import_path)
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 680,
in import_module
    execfile(file, module.__dict__)
  File "/home/tom/dev/auth/ssofilter-apache-2.2/startup.py", line 4, in
<module>
    cipher = apache.import_module('ncrypt.cipher')
  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304,
in import_module
    return __import__(module_name, {}, {}, ['*'])
  File "/var/lib/python-support/python2.5/ncrypt/cipher.py", line 1, in
<module>
    from _ncrypt.cipher import *
ImportError: No module named cipher
[Tue Feb 05 14:34:25 2008] [error] directive_PythonImport: error importing
startup

The first interpreter imports the module fine (as seen by ******** IMPORTED
log entry), but the second one fails (two exceptions).

So after some head-scratching came upon a theory - the ncrypt package is a
binary .so (called _ncrypt), and maybe it doesn't like being loaded twice
into the same process (not sure about unix, but in the windows environment
have come across similar dll loading issues). So tried a couple of other
binary packages such as socket which did work. So i've decided to ditch
ncrypt as my cryptography package and have opted to use pycrypto instead
(and which is happy being imported twice).

Guess I should post this off to the ncrypt mailing list too!

Ciao,
Tom


On Feb 5, 2008 12:27 AM, Graham Dumpleton <graham.dumpleton at gmail.com>
wrote:

> What settings do you have in your configuration for:
>
>  PythonPath ...
>  PythonOption mod_python.importer.path ...
>
> The module importer doesn't add paths automatically to sys.path and
> uses its own path which is in part based on the request context. The
> locations it can look in can therefore vary based on where your
> handler code is located which the request mapped to. As such, you may
> need to explicitly set the module importer path option if a specific
> directory must always be checked.
>
> The other option is that if you are relying on being able to import
> from a module installed on sys.path, ie., standard module, a module
> which only exists somewhere on mod_python module path. You can't do
> this, when using 'import' in a standard Python module, it will only
> look for stuff on sys.path.
>
> Answer these questions, but also make sure you have read up on
> import_module function in:
>
>  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html
>
> if you haven't done so already.
>
> Graham
>
> On 05/02/2008, Tom Wells <drshade at gmail.com> wrote:
> > 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]
> >
> >
> >
> >
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> >
> >
>



-- 
http://www.tomwells.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20080205/ea7cee6d/attachment-0001.html


More information about the Mod_python mailing list