Thread: [SQLObject] SQLObject+Quixote+SCGI
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2004-10-24 12:04:39
|
Hello! As far as I understand more and more people use SQLObject+Quixote these days. There is a question I'd like to ask. People, how do you handle forks and transactions? I use Quixote+SCGI(+Apache); my program is a long-living (Quixote) forking (SCGI) process. The thing that is worrying me is that I import a module that defines my tables almost before anything else. The module opens a connection to a Postgres database, and then SCGI forks the program. Should I worry? Shoud I close and reopen the connection? What about transactions? Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Ksenia M. <ks...@ks...> - 2004-10-27 09:15:45
|
Op 24-okt-04 om 14:04 heeft Oleg Broytmann het volgende geschreven: > People, how do you handle forks and transactions? > > I use Quixote+SCGI(+Apache); my program is a long-living (Quixote) > forking (SCGI) process. The thing that is worrying me is that I import > a > module that defines my tables almost before anything else. The module > opens a connection to a Postgres database, and then SCGI forks the > program. > Should I worry? Shoud I close and reopen the connection? What about > 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 find. Maybe it's related to the forking problem? More comments are greatly appreciated... Ksenia. |
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. |
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. |