How do you get persistent database connections with Python?
gh_pythonlist at gmx.de
Wed Nov 14 05:01:41 CET 2001
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
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).
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