Usage

So, to transform your class into a replicated one: - Inherit it from
SyncObj - Initialize SyncObj with a self address and a list of partner
addresses. Eg. if you have serverA, serverB and serverC and
want to use 4321 port, you should use self address serverA:4321 with
partners [serverB:4321, serverC:4321] for your application, running
at serverA; self address serverB:4321 with partners
[serverA:4321, serverC:4321] for your application at serverB;
self address serverC:4321 with partners
[serverA:4321, serverB:4321] for app at serverC. - Mark all your
methods that modifies your class fields with @replicated decorator.
So your final class will looks like:

Batteries

frompysyncobjimportSyncObjfrompysyncobj.batteriesimportReplCounter,ReplDictcounter1=ReplCounter()counter2=ReplCounter()dict1=ReplDict()syncObj=SyncObj('serverA:4321',['serverB:4321','serverC:4321'],consumers=[counter1,counter2,dict1])counter1.set(42,sync=True)# set initial value to 42, 'sync' means that operation is blockingcounter1.add(10,sync=True)# add 10 to counter valuecounter2.inc(sync=True)# increment counter value by onedict1.set('testKey1','testValue1',sync=True)dict1['testKey2']='testValue2'# this is basically the same as previous, but asynchronous (non-blocking)print(counter1,counter2,dict1['testKey1'],dict1.get('testKey2'))

Lock

frompysyncobjimportSyncObjfrompysyncobj.batteriesimportReplLockManagerlockManager=ReplLockManager(timeout=75)# Lock will be released if connection dropped for more than 75 secondssyncObj=SyncObj('serverA:4321',['serverB:4321','serverC:4321'],consumers=[lockManager])iflockManager.tryAcquire('testLockName',sync=True):# do some actionslockManager.release('testLockName')