views:

30

answers:

1

I want to use MySQLdb in Pylons, but can't figure out where to actually connect. It would seem that making the connection in app_globals.py would be convenient:

class Globals(object):
    def __init__(self):
        self.db = MySQLdb.connect()

Then controllers can access the db via the globals. However, this seems to lead to problems with 'MySQL has gone away' errors, and crashes with concurrent requests, so I'm thinking that this is bad because of thread safety.

What is the best way to do this? Should each controller open and then close a MySQL connection? Thanks!