On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch" <deets@nospam.w eb.dewrote:
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
>Jean-Paul Calderone wrote:
>
>
>Be aware that this isn't working concurrently. Depending on your
>application, this can be mitigated using a simple threading.Lock.
>
>
>On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
><phillip.oldha m@gmail.comwrot e:
>>
>Here's one way
>>
> class Sequence(Persis tence):
> def __init__(self):
> self.current = 0
>>
> def next(self):
> self.current += 1
> return self.current
>>
> ticketSequence = Sequence()
>>
> class Ticket(Persiste nce):
> def __init__(self):
> self.id = ticketSequence. next()
><phillip.oldha m@gmail.comwrot e:
>>[snip]
>>>
>>>How would one assign a unique ID to the root at that point?
>>>
>>>How would one assign a unique ID to the root at that point?
>Here's one way
>>
> class Sequence(Persis tence):
> def __init__(self):
> self.current = 0
>>
> def next(self):
> self.current += 1
> return self.current
>>
> ticketSequence = Sequence()
>>
> class Ticket(Persiste nce):
> 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.
>
code safe for concurrent use. A threading.Lock would make threaded
use safe, but wouldn't give you multiprocess concurrency safety.
Jean-Paul
Comment