[mod_python] import errors

Craig Warren craig.warren at encorp.com
Wed Sep 15 13:37:41 EDT 2004


I am just starting to use mod_python and I am see a strange
behavior.  I have a handler (XMLRPC) that is import another file of mine
(node.py).  The imported file seems to get imported for every thread (ie
the code gets run multiple times, once for each tread (I think)). 
Anybody have any ideas why? I have checked and it is using the same
interpreter.  I would think that once it is imported, it wouldn't get
imported again and the code wouldn't run.

In my handler xmlrpc.py  I have the following

  node = apache.import_module('mod_python.node',1,1)

and I have also used  (with the same affect)

   from mod_python import node

In my node.py file I have the following to print to the log

def log(msg):
    if debug:  
        apache.log_error('DEBUG:%s' % msg)
import sys
log('Importing node.py...') 
log('module is in sys.modules Modules for sys.modules:%s' %
sys.modules['mod_python.node'])


Below is output from the error_log that I printed to.   You can see it
gets imported 8 times. In my httpd.conf file I have the following
configuration.
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
MaxClients       150
MaxRequestsPerChild  4000
</IfModule>


Log File:
[Wed Sep 15 12:16:16 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:16 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:16 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:16 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:18 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:18 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:20 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:20 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:22 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:22 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:24 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:24 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:26 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:26 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>
[Wed Sep 15 12:16:28 2004] [error] DEBUG:Importing node.py...
[Wed Sep 15 12:16:28 2004] [error] DEBUG:module is in sys.modules
Modules for sys.modules:<module 'mod_python.node' from
'/usr/lib/python2.3/site-packages/mod_python/node.py'>


Thanks for any help in advance.

Craig Warren

-- 
Craig Warren
Senior Programmer       
Encorp
craig.warren at encorp.co



More information about the Mod_python mailing list