[Zope] Which method to generate IDs for objects?

Dieter Maurer dieter@handshake.de
Sun, 20 Jan 2002 23:15:12 +0100


Thomas Guettler writes:
 > > It is therefore better, to use the "_setObject" directly:
 > > 
 > >    while 1:
 > >      try: self._setObject(str(intid),o); break;
 > >      except BadRequest: intid= intid+1
 > 
 > Sorry, I don't understand this. Ain't there a easier way to get
 > something like a syncronized block in java?
The standard Zope execution is easier than explicit synchronization:
you do not need to synchronize. Details in a paper about ZODB3 on
Zope.org.

But in rare cases, you might get a "BadRequest" exception, unless
you are carefull. Assigning ids can be one such case.

You can use locking in Zope, too. See "SharedResource" on

  <http://www.dieter.handshake.de/pyprojects/zope>


 > BTW, I found something in lib/python/ZODB/tests/ConflictResolution.py:
 > The PCounter class. I think it is a persistent thread safe counter.
Thank you for this hint.


Dieter