On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]>
wrote:
Jean-Paul Calderone wrote:
On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
<[EMAIL PROTECTED]> wrote:
[snip]
How would one assign a unique ID to the root at that point?
Here's one way
class Sequence(Persistence):
def __init__(self):
self.current = 0
def next(self):
self.current += 1
return self.current
ticketSequence = Sequence()
class Ticket(Persistence):
def __init__(self):
self.id = ticketSequence.next()
Be aware that this isn't working concurrently. Depending on your
application, this can be mitigated using a simple threading.Lock.
ZODB has transactions. That's probably the best way to make this
code safe for concurrent use. A threading.Lock would make threaded
use safe, but wouldn't give you multiprocess concurrency safety.
Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list