[mod_python] Problem keeing the db connection open

Jalil Feghhi jalil at securia.com
Mon Dec 22 15:49:53 EST 2003


I found the following code on the Internet for keeping the connection
open but it doesn't really work. Everytime I try to login, it connects
to the database. I put some log messges and I can see this happens.

1. Could someone tell me how I can keep the connection open? 

2.  I appreciate if someone explain how mod_python handler is called
when there are many requests? Does Apache create threads for each
request? And how the global database connection is used?

Thanks,

-Jalil

Here is the code:

HOST = "localhost"

DB = "mydb"

USER = "user"

PASS = "pwd"

import MySQLdb

import string

def _db_login(relogin = 0):


    global DB_CONN

    if relogin:

        DB_CONN = MySQLdb.connect(db=DB, user=USER, passwd=PASS)

        return DB_CONN

    else:

        try:

            d = DB_CONN

            return d

        except NameError:

            DB_CONN = MySQLdb.connect(host= HOST, db=DB, user=USER,
passwd=PASS)

            return DB_CONN

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.modpython.org/pipermail/mod_python/attachments/20031222/bad48455/attachment-0003.htm


More information about the Mod_python mailing list