pysyncobj.batteries package¶
ReplCounter¶
-
class
pysyncobj.batteries.
ReplCounter
¶ Simple distributed counter. You can set, add, sub and inc counter value.
-
add
(value)¶ Adds value to a counter.
- Parameters
value – value to add
- Returns
new counter value
-
get
()¶ - Returns
current counter value
-
inc
()¶ Increments counter value by one.
- Returns
new counter value
-
set
(newValue)¶ Set new value to a counter.
- Parameters
newValue – new value
- Returns
new counter value
-
sub
(value)¶ 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
(item)¶ Append item to end
-
count
(element)¶ Return number of occurrences of element
-
extend
(other)¶ 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
(position, element)¶ Insert object before position
-
pop
(position=None)¶ 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
(element)¶ Remove first occurrence of element. Raises ValueError if the value is not present.
-
reset
(newData)¶ Replace list with a new one
-
set
(position, newValue)¶ Update value at given position.
-
sort
(reverse=False)¶ Stable sort IN PLACE
-
ReplDict¶
-
class
pysyncobj.batteries.
ReplDict
¶ Distributed dict - it has an interface similar to a regular dict.
-
clear
()¶ 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
(key, default=None)¶ Remove and return value for given key, return default if key not exist
-
rawData
()¶ Return internal dict - use it carefully
-
reset
(newData)¶ Replace dict with a new one
-
set
(key, value)¶ Set value for specified key
-
setdefault
(key, default)¶ Return value for specified key, set default value if key not exist
-
update
(other)¶ 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
(item)¶ Add an element to a set
-
clear
()¶ Remove all elements from this set.
-
discard
(item)¶ Remove an element from a set if it is a member. If the element is not a member, do nothing.
-
pop
()¶ Remove and return an arbitrary set element. Raises KeyError if the set is empty.
-
rawData
()¶ Return internal dict - use it carefully
-
remove
(item)¶ Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError.
-
reset
(newData)¶ Replace set with a new one
-
update
(other)¶ 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
(default=None)¶ Extract item from queue. Return default if queue is empty.
-
put
(item)¶ 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
(default=None)¶ Extract the smallest item from queue. Return default if queue is empty.
-
put
(item)¶ 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