[mod_python] Problem with PythonImport

Graham Dumpleton grahamd at dscpl.com.au
Mon Dec 26 22:56:36 EST 2005


You still need to import your module in your PSP code. All the  
PythonImport
statement does is preload the module prior to any request being handled
such that code with side effects can be done early. Just like any  
other Python
module, it has to use "import" statement to import anything it wants  
to use,
even if already imported by some other separate module/code. More  
comments
below.

On 27/12/2005, at 4:44 AM, Rafal Zawadzki wrote:

> Hi. At the beginning I have to say that I read:
>
> * thread called "PythonImport: Can someone please draw a diagram  
> for this
> idiot?" and others similar ;>
> * documentation about PythonImport
>
> I am writing web application using modpython 3.1 + psp. I am using  
> apache2, my
> apache2.conf contains:
>
> PythonImport Baza glam.idoru
> PythonOptimize on
>
> and file of my virtual host contains:
>
> <Directory /home/bluszcz/www/glam.idoru>
> DirectoryIndex index.psp index.html
> AddHandler mod_python .psp
> PythonHandler mod_python.psp
> PythonDebug On
> PythonPath "sys.path+['/home/bluszcz/www/glam.idoru']"
> AllowOverride None
> </Directory>
>
> cat testimport.py
>
> <%

import Baza

> req.write(str(dir()))
> req.write("<br />")
> req.write(str(req.interpreter))
> %>
>
>
> links -dump http://glam.idoru/admin/testimport.psp
>
> gives me:
>
> ['FileCache', 'HitsCache', 'PSP', 'PSPInterface', 'Session',  
> '__builtins__',
> '__doc__', '__file__', '__mtime__', '__name__', '_apache', '_psp',  
> 'anydbm',
> 'apache', 'code2str', 'dbm_cache_get', 'dbm_cache_store',  
> 'dbm_cache_type',
> 'dbm_types', 'escape', 'form', 'handler', 'marshal', 'mem_fcache',
> 'mem_scache', 'new', 'os', 'parse', 'parsestring', 'path_split',  
> 'psp',
> 'req', 'session', 'str2code', 'sys', 'tempdir', 'tempfile', 'util',
> 'whichdb']
> glam.idoru
>
>
> My question is how can I get to my "Baza" module? I am trying to  
> use it with
> persisten database connection (there is no enough docs about it!).  
> Module
> Baza is has been loaded (i tried to put into this command creating  
> dir, and
> it works).

There are downsides to using PythonImport to initialise database  
connections
as a side effect. Namely, if it fails, if you don't have fallback  
means of having the
database connections initialised, you have to restart Apache. Thus,  
you need
to make sure you do it properly.

See mailing list threads:

   http://www.modpython.org/pipermail/mod_python/2005-October/ 
019287.html
   http://www.modpython.org/pipermail/mod_python/2005-September/ 
019092.html

Also be aware that current versions of mod_python have various issues  
with
module importing in general, see:

   http://www.dscpl.com.au/articles/modpython-003.html

Graham

  
  


More information about the Mod_python mailing list