[Zope] Counter and concurrent access

Yann Lugrin yann.lugrin@gmproject.net
Mon, 24 Sep 2001 17:05:58 +0200


Hello,

I try to create a counter of which I am certain that it sends back in every
Call a different result. I should so manage concurent acces on this one.

The following method is not valid I have to look for a product which could make
works:
----
ID = context.nextID
context.manage_changeProperties( { 'nextID' : ID+1 } )
----

But products found (FSCounter and to threadSafeCounter) uses the
File System to manage the concurrent access on the counter value.

I want to use the method described in the article " Advanced ZODB for python
Programmers " ( Http://www.zope.org/Documentation/Articles/ZODB2) by creating a
product based on the following code:

------------
class Counter(Persistent):
    self.count = 0

    def hit(self):
        self.count = self.count + 1
        return self.count

    def _p_resolveConflict(self, oldState, savedState, newState):
        # Figure out how each state is different:
        savedDiff= savedState['count'] - oldState['count']
        newDiff= newState['count']- oldState['count']        
        
        # Apply both sets of changes to old state:
        return oldState['count'] + savedDiff + newDiff
----------

Is the class "Persistent" assure the value " self.count " to be not identical in
two simultaneous calls of the "hit" method (not identical return value)?


--
Yann Lugrin
yann.lugrin@gmproject.net