Re: [SQLObject] ? Treadsafety, transactions, DB-API ?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2003-06-11 19:33:47
|
On Wed, 2003-06-11 at 12:38, Bud P.Bruegger wrote: > Can someone help me calm my mental storm stemming from a confusion > and lack of understanding on treadsafety, transactions, and DB-API? > > For SQLObject to be threadsafe, do threads need an isolation of their > transactions? It seems so, since one thread will typically want to > commit while another one is in the middle of its transaction... Right now you do transactions something like: someConn = PostgresConnection(...) trans = someConn.transaction() myObj1 = MyObject(connection=trans) ... trans.commit() > But then again, if multiple threads modify the same > objects (in memory), does isolation of transactions really guarantee > consistency? It seems that this could only be true if there > were locks on application objects. For example, a multi-threaded app > that transfers funds between instances of Account would probalby have > to lock (or version) affected Account instances for the duration of a > transaction such that no other thread can debit or accredit funds and > mess up consistency. Does SQLObject do something of this sort or has > my reasoning gone astray somewhere? There's no locking implemented. We've talked about some ideas... I seem to remember you being the one that initially brought it up ;) If you *don't* use transactions, then you can be sure that each object is the only instance of that object (for that id) in the process. So you can put locks on the object itself. Like: class Account(SQLObject): def _init(self, id): SQLObject._init(self, id) self.lock = threading.Lock() acct = Account(10) acct.lock.acquire() ... acct.lock.release() Doesn't work if you have more than one process accessing the database at a time, and they all need to be locked. > Also, in my (probably faulty) understanding of the DB-API, > transactions are properties of connections. Does that mean that > different threads need to use different connections? Does SQLObject > do that? Yes, that's what .transaction() does. Ian |