Alexander Staubo <alex@mop.no> writes:
You can store a "last ID" counter as an int property on the top-level folder, and increment that for every object you create.
Under Zope2 the counter must be thread-safe, which means you've got to borrow of Zope's global -- I think -- thread locks.
If the object is persistent, like a property, it is automaticly thread safe.
Thread safe yes, but not atomic. In other words, the operation (done in an External Method or whatever) NewObjectId = Counter = Counter + 1 isn't atomic. This is really not of relevance here since only a _unique_ object ID is desired -- I didn't think of that when I said it mus tbe thread safe -- but in cases where you'd want a guaranteed _sequential_ counter, you would risk holes in your sequence as the interpreter thread could be pre-empted at any time during the execution of the statement. Now, I don't know if the Python global interpreter lock permit statements to be interrupted. Does it? In that case, chalk that up as just another moot point :-) -- Alexander Staubo http://www.mop.no/~alex/ "What the hell, he thought, you're only young once, and threw himself out of the window. That would at least keep the element of surprise on his side." --Douglas Adams, _The Hitchhiker's Guide to the Galaxy_