pysyncobj.batteries package

ReplCounter

class pysyncobj.batteries.ReplCounter

Simple distributed counter. You can set, add, sub and inc counter value.

add(*args, **kwargs)

Adds value to a counter.

Parameters:value – value to add
Returns:new counter value
get()
Returns:current counter value
inc(*args, **kwargs)

Increments counter value by one.

Returns:new counter value
set(*args, **kwargs)

Set new value to a counter.

Parameters:newValue – new value
Returns:new counter value
sub(*args, **kwargs)

Subtracts a value from counter.

Parameters:value – value to subtract
Returns:new counter value

ReplList

class pysyncobj.batteries.ReplList

Distributed list - it has an interface similar to a regular list.

append(*args, **kwargs)

Append item to end

count(element)

Return number of occurrences of element

extend(*args, **kwargs)

Extend list by appending elements from the iterable

get(position)

Return value at given position

index(element)

Return first position of element. Raises ValueError if the value is not present.

insert(*args, **kwargs)

Insert object before position

pop(*args, **kwargs)

Remove and return item at position (default last). Raises IndexError if list is empty or index is out of range.

rawData()

Return internal list - use it carefully

remove(*args, **kwargs)

Remove first occurrence of element. Raises ValueError if the value is not present.

reset(*args, **kwargs)

Replace list with a new one

set(*args, **kwargs)

Update value at given position.

sort(*args, **kwargs)

Stable sort IN PLACE

ReplDict

class pysyncobj.batteries.ReplDict

Distributed dict - it has an interface similar to a regular dict.

clear(*args, **kwargs)

Remove all items from dict

get(key, default=None)

Return value for given key, return default if key not exist

items()

Return all items

keys()

Return all keys

pop(*args, **kwargs)

Remove and return value for given key, return default if key not exist

rawData()

Return internal dict - use it carefully

reset(*args, **kwargs)

Replace dict with a new one

set(*args, **kwargs)

Set value for specified key

setdefault(*args, **kwargs)

Return value for specified key, set default value if key not exist

update(*args, **kwargs)

Adds all values from the other dict

values()

Return all values

ReplSet

class pysyncobj.batteries.ReplSet

Distributed set - it has an interface similar to a regular set.

add(*args, **kwargs)

Add an element to a set

clear(*args, **kwargs)

Remove all elements from this set.

discard(*args, **kwargs)

Remove an element from a set if it is a member. If the element is not a member, do nothing.

pop(*args, **kwargs)

Remove and return an arbitrary set element. Raises KeyError if the set is empty.

rawData()

Return internal dict - use it carefully

remove(*args, **kwargs)

Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError.

reset(*args, **kwargs)

Replace set with a new one

update(*args, **kwargs)

Update a set with the union of itself and others.

ReplQueue

class pysyncobj.batteries.ReplQueue(maxsize=0)

Replicated FIFO queue. Based on collections.deque. Has an interface similar to Queue.

Parameters:maxsize (int) – Max queue size.
empty()

True if queue is empty

full()

True if queue is full

get(*args, **kwargs)

Extract item from queue. Return default if queue is empty.

put(*args, **kwargs)

Put an item into the queue. True - if item placed in queue. False - if queue is full and item can not be placed.

qsize()

Return size of queue

ReplPriorityQueue

class pysyncobj.batteries.ReplPriorityQueue(maxsize=0)

Replicated priority queue. Based on heapq. Has an interface similar to Queue.

Parameters:maxsize (int) – Max queue size.
empty()

True if queue is empty

full()

True if queue is full

get(*args, **kwargs)

Extract the smallest item from queue. Return default if queue is empty.

put(*args, **kwargs)

Put an item into the queue. Items should be comparable, eg. tuples. True - if item placed in queue. False - if queue is full and item can not be placed.

qsize()

Return size of queue

ReplLockManager

class pysyncobj.batteries.ReplLockManager(autoUnlockTime, selfID=None)

Replicated Lock Manager. Allow to acquire / release distributed locks.

Parameters:
  • autoUnlockTime (float) – lock will be released automatically if no response from holder for more than autoUnlockTime seconds
  • selfID (str) – (optional) - unique id of current lock holder.
destroy()

Destroy should be called before destroying ReplLockManager

isAcquired(lockID)

Check if lock is acquired by ourselves.

Parameters:lockID (str) – unique lock identifier.

:return True if lock is acquired by ourselves.

release(lockID, callback=None, sync=False, timeout=None)

Release previously-acquired lock.

Parameters:
  • lockID (str) – unique lock identifier.
  • sync (bool) – True - to wait until lock is released or failed to release.
  • callback (func(opResult, error)) – if sync is False - callback will be called with operation result.
  • timeout (float) – max operation time (default - unlimited)
tryAcquire(lockID, callback=None, sync=False, timeout=None)

Attempt to acquire lock.

Parameters:
  • lockID (str) – unique lock identifier.
  • sync (bool) – True - to wait until lock is acquired or failed to acquire.
  • callback (func(opResult, error)) – if sync is False - callback will be called with operation result.
  • timeout (float) – max operation time (default - unlimited)

:return True if acquired, False - somebody else already acquired lock