Re: [SQLObject] SQLObject+Quixote+SCGI
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ksenia M. <ks...@ks...> - 2004-10-28 23:26:37
|
> > Well, now I do as follows. Firest, transactions. I initialize > transactions in my DB.py, where I declare all my tables: > > from Cfg import dbName, dbUser, dbPassword, dbHost > dbConn = PostgresConnection(db=dbName, user=dbUser, passwd=dbPassword, > host=dbHost) > dbConn.debug = True > > transaction = dbConn.transaction() > transaction._makeObsolete() # prepare for .begin() > > def transaction_begin(): > transaction.begin() > > def transaction_commit(): > transaction.commit() > > def transaction_rollback(): > transaction.rollback() > > > # the parent class for all my tables > class Table(SQLObject): > _connection = transaction > > > In the main script: > > class MyPublisher(Publisher): > > def process_request(self, request, env): > from DB import transaction_begin, transaction_commit, > transaction_rollback > transaction_begin() > try: > output = Publisher.process_request(self, request, env) > except: > transaction_rollback() > raise > else: > transaction_commit() > return output > > > Second, forking. I have to delay importing DB until after forking. > Actually, I import it now only when it is required. In main script > right > in process_request(), in other modules - in appropriate methods. This > late import delays creating the connection, so the real connection to > the database is being created late enough - after SCGI has forked. > Thank you for sharing - it was very helpful! Ksenia. |