[ZODB-Dev] Items committed in one thread not seen in anotherthread?

Tim Peters tim at zope.com
Wed Mar 9 15:32:14 EST 2005


[Gwyn Evans]
>>> The persistance is done as below, where d = a dictionary -
>>>
>>>   self.dbRoot[recId] = d
>>>   get_transaction().commit()

[Christian Robottom Reis]
>> A thread has a local view of its object, and modifications made in other
>> threads are not visible "automatically": you need to call sync() on the
>> connection, or abort()/commit() a transaction.

[Gwyn Evans]
>   Thanks - I've already been committing the transaction as above (or
> have I? Do I need to explicitly start one?)

You're always "in" a transaction, but that's true of _all_ threads you're
running, and different threads are "in" different transactions.  The thread
in which you're doing the commit() is in no trouble here, but presumably you
were never crossing a transaction boundary in the thread you hoped would see
the changes committed by the former thread.  Yhat latter thread is in a
transaction too, and won't see any changes until it also crosses a
transaction boundary, or ...

> but I've not tried sync() yet, so will investigate that...

... or it does sync() on its Connection.  The first thing sync() does under
the covers is get_transaction().abort(), which causes the thread calling
sync() to cross a transaction boundary.

Thread safety in ZODB is provided by giving each thread its own
transactional view of object states, instead of by user-level locking.
That's most convenient most often, but means you have to "do something" if
you want a thread to see changes committed by other threads (or by other
processes, for that matter).



More information about the ZODB-Dev mailing list