[Zope] Which method to generate IDs for objects?

Thomas Guettler Thomas Guettler <thomas@thomas-guettler.de>
Wed, 16 Jan 2002 18:55:19 +0100


On Wed, Jan 16, 2002 at 12:21:45PM -0000, Tim Hicks wrote:
> 
> I don't know if this is very efficient/elegant/etc*, but I use it to get a
> unique id within a folder...
> 
> -------------
> intid = 1
> while 1:
>    if hasattr(photo_folder, str(intid)):
>      intid = intid + 1
>    else:


How thread-safe is this? I Java I would write a syncronise block
around i=i+1, because of the following example:

Timestep 1: i==5; two threads read it
Timestep 2: both do i=5+1

--> There will be two Classes with id==6. I have seen a counter object
somewhere. I think it is thread safe.

Is there something like syncronise blocks in python/zope?

-- 
Open Source Software Solutions 
Thomas Guettler <guettli@thomas-guettler.de>
http://www.thomas-guettler.de