[mod_python] Re: Single Persisten DB conn across multiple connections

Chris Jackson christopher.jackson at gmail.com
Wed Feb 9 19:17:39 EST 2005


I've been reading this FAQ:

http://www.modpython.org/FAQ/faqw.py?req=show&file=faq03.018.htp

However, it doesn't answer my question of how to use one connection
accross multiple sessions.
It ends in saying:

"My advice is to renew database connections, configs and everything
you have to load for a request every hit during development. After
you're done coding and it turnes out that it's not fast enough:
profile..."

~= Chris =~


On Wed, 9 Feb 2005 18:57:40 -0500, Chris Jackson
<christopher.jackson at gmail.com> wrote:
> 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.
> 
>            DB
>              |
>  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.
> 
> Thanks,
> 
> ~= Chris =~
>


More information about the Mod_python mailing list