How do you get persistent database connections with Python?

mark at laptop.local mark at laptop.local
Wed Nov 14 17:29:08 CET 2001


In article <mailman.1005714200.2375.python-list at python.org>,
Gerhard =?iso-8859-1?Q?H=E4ring?=  <gh_pythonlist at gmx.de> wrote:
>On Tue, Nov 13, 2001 at 08:30:51PM -0500, mark at laptop.local wrote:
>> How do you create persistent database connections with Apache, Python, 
>> and PostgreSQL? Any generic methods of creating persistent database connections
>> would be helpful.
>> 
>> I have been trying like crazy to find information on the topic, but I can't
>> find any useful information. 
>> 
>> I am using mod_python and also PyGreSQL modules. I can switch to others
>> if need be.
>
>The db module doesn't matter. What you probably need to check out is the
>Python documenation (wrt. importing modules). Your mod_python handler
>lives as long as the Apache process lives.
>
>So, you just have to instantiate a db connection in the handler's module
>and store the connection object it in the module. That's all there is to
>it.
>
>There are three alternatives to PyGreSQL: pyPgSQL, psycopg and PoPy (I'm
>a developer in the pyPgSQL project). I'd recommend you check out the
>alternatives, too if you're interested in a good db module 4 PG. Iff you
>want to continue using PyGreSQL, I recommend you check out the latest
>version from *PostgreSQL* CVS - it contains several bugfixes when
>compared to the latest "released" version of PyGreSQL (3.2).

Ah, thanks for the advice!
I tried to create global variables, but they didn't persistent from
session to session. Of course, I had the global variables in he scripts,
perhaps I should try them in modules. I wonder what happnes to global
variables in scripts? It seems like they don't stay global the next
time th hanlder runs. I should try it with modules though. 

Mark

>
>Gerhard
>-- 
>mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
>web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
>public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
>reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
>





More information about the Python-list mailing list