PyProcSync

class pyprocsync.pyprocsync.ProcSync(redis_client: redis.client.Redis, run_id: str = '', delay: float = 1.0)[source]

Bases: object

PyProcSync main class.

An instance of class represents a single “run” with their own Redis connection. Each synchronization point (sync() calls) is tied to the context of a ProcSync instance with an unique run_id.

Upon creation the appropriate channel is being subscribed to.

Although the run_id is optional it is strongly recommended to be set to a different value at each creation. The run_id must be the same on all nodes that takes part of the same “run”.

Parameters
  • redis_client – A redis.Redis instance that’s connected to a redis server.

  • run_id – An arbitrary id (str) that identifies this specific run. (Should be unique across all runs and the same on all nodes)

  • delay – Time spent waiting after the continue time is announced. (Default is 1 sec)

close()[source]

Close Redis connection. After calling this method. The instance should not be used anymore.

sync(event_name: str, nodes: int, timeout: Optional[float] = None)[source]

Start waiting for each node (number of nodes specified by nodes parameter) to arrive at the synchronization point specified by event_name.

WARNING: All parameters of this method MUST BE the same on every node for the same event (including timeout). If parameters supplied for this method differ from other nodes, this would not only cause malfunction in the current instance but would confuse other nodes waiting for this synchronization point as well!

If configured properly, this method returns at the same time (according to their system clock) on all nodes.

Exceptions this method may raise:
  • ValueError: Some parameters are invalid.

  • pyprocsync.TooLateError: Synchronization time already expired when recieved (system clocks not in sync or configured delay lower than network latency)

  • pyprocsync.TimeOutError: (only when timeout is not none) Given up waiting for other nodes.

  • AssertionError: Unexpected values read from Redis.

  • Redis related exceptions (see. pyredis docs).

Parameters
  • event_name – The name of the event. This is the same across all nodes that want to synchronize.

  • nodes – Amount of nodes to sync the event between.

  • timeout – Maximum time to wait for all nodes to reach the synchronization point defined by event_name in seconds. Set to None for infinite wait time. TimeOutError raised when the timeout expire.