[Zope] Question about ZODB and threads

Pavlos Christoforou pavlos@gaaros.msrc.sunysb.edu
Wed, 13 Oct 1999 22:07:28 -0400 (EDT)


Hello Zopistas -

Suppose we have a persistent object registered with ZODB which has a list
attribute contents. According to ZODB rules we should treat mutable
attributes as immutable, but what happens if we are crazy enough to treat
them as mutable and do things like:

self.contents.append('crazy')

Had we treated it as immutable we would have done something like:

tmp=self.contents
tmp.append('not so crazy')
self.contents=tmp


in which case tmp is local to the thread and the last statement triggers
ZODB's thread-safe transaction mechanism. However in the first case ZODB
is unaware of the modification. This was not a problem before the
concurrent ZODB, but I am not sure what would happen if two threads call
this function simultaneously. Any ideas? (No it is not a theoretical
question. Such a construct can be very useful in many situations where you
might want to store data in memory temporarily.)

Happy Zopping

Pavlos