Re: [SQLObject] SQLObject+Quixote+SCGI
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ma...> - 2004-10-27 10:36:46
|
On Wed, Oct 27, 2004 at 11:15:29AM +0200, Ksenia Marasanova wrote: > Op 24-okt-04 om 14:04 heeft Oleg Broytmann het volgende geschreven: > > People, how do you handle forks and transactions? > > I am on the same path (SQLObject + Quixote + SCGI), but earlier - > worring about more primitive things yet :) But I share your concern. > There is a mention of preferred connection approach in Quixote on this > page: http://wiki.sqlobject.org/connections.html, but it's all I can I saw it already, of course. Actually, I have searched SQLObject and Quixote mailing lists using Google and Gmane. > find. Maybe it's related to the forking problem? > More comments are greatly appreciated... 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. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |