[mod_python] Single Persisten DB conn across multiple connections

Chris Jackson christopher.jackson at gmail.com
Wed Feb 9 18:57:40 EST 2005

What is the best way, or at least some way to create a single database
connection object in mod_python and have everyone who connects use
that same DB connection.

Note: I'm using the publisher handler.

 DBconn object
       /     |    \
user  user  user

My original theory (tested, doesn't work -- Multiple DB Connections are made):

To create a global DBconn object and have each session rely on the
same global variable.
The idea fails I think because multiple interpreters are created with
each apache child process,
and so global variables are re-instantiated.

New theory(untested):

Make the DBconn object outside in a separate module so that python
only imports the module
once, hence using only a single DBconn object.  In this case module
space is consistent even
with multiple interpreters.

Any comments and/or solutions would be gladly appreciated.


~= Chris =~

More information about the Mod_python mailing list