[mod_python] PythonImport: Can someone please draw a diagram forthis idiot?

jamestmcneill-python at yahoo.co.uk jamestmcneill-python at yahoo.co.uk
Wed Sep 14 07:00:42 EDT 2005


Nicolas,

Thanks for that. Unfortunately I find that it doesn't really get me any
further. Using mpglobals.cur.execute just lets me know that it isn't
defined either ("NameError: global name 'mpglobals' is not defined" -
starting IDLE and looking at sys.path confirms that the directory is there
in the penultimate position), and trying to import it every time I service
a request kind of defeats the purpose, which is putting the database
connection handler into PythonImport to avoid the overhead involved in
it's creation at request time. As the manual says about PythonImport:
"This is useful for initialization tasks that could be time consuming and
should not be done at the request processing time, e.g. initializing a
database connection."

I must admit that this is one of the key reasons for me to look at
mod_python at all, and honestly I haven't started dropping questions into
the mailing list until I'd exhausted everything I could find in the
archives and google etc. There are a couple of examples in the FAQ on
"3.3. What is the best way to make persistent connections to a database?",
but I must admit to not being able to understand how this code is to be
worked into which stage of Apache handling, as surely as it reads it is
not intended to be run with every request?

As with my previous questions on ClearSilver, what I'd like to do is to
devise a minimal example of the use of PythonImport for creating permanent
database connections, as the manual states is possible.

Regards,
Jim

--- Nicolas Lehuen <nicolas.lehuen at gmail.com> wrote:

> Instead of "cur.execute" write "mpglobals.cur.execute".
> 
> Or, if mpglobals is really on the sys.path, then you can drop
> PythonImport 
> and write :
> 
> from mpglobals import cur # or import * if you want all
> cur.execute(...)

++++++++++++++++++++++++++++++++++++++++++++++++++
+   If you've got a good excuse - don't use it   +
++++++++++++++++++++++++++++++++++++++++++++++++++)



More information about the Mod_python mailing list