class documentation

Base class for a shared state manager providing cross-process-safe primitives for use by activity executors.

Cross-worker use of the shared state manager is encouraged. create_from_multiprocessing provides the commonly used implementation.

Static Method create_from_multiprocessing Create a shared state manager from a multiprocessing manager.
Method new_event Create a threading.Event that can be used across processes.
Async Method register_heartbeater Register a heartbeat function.
Async Method unregister_heartbeater Unregisters a previously registered heartbeater for the task token. This should also flush any pending heartbeats.
@staticmethod
def create_from_multiprocessing(mgr: multiprocessing.managers.SyncManager, queue_poller_executor: Optional[concurrent.futures.Executor] = None) -> SharedStateManager: (source)

Create a shared state manager from a multiprocessing manager.

Parameters
mgr:multiprocessing.managers.SyncManagerSync manager to create primitives from. This is usually multiprocessing.Manager.
queue_poller_executor:Optional[concurrent.futures.Executor]The executor used when running the synchronous heartbeat queue poller. This should be a concurrent.futures.ThreadPoolExecutor. If unset, a thread pool executor is created with max-workers of 1.
Returns
SharedStateManagerThe shared state manager.
@abstractmethod
def new_event(self) -> threading.Event: (source)

Create a threading.Event that can be used across processes.

@abstractmethod
async def register_heartbeater(self, task_token: bytes, heartbeat: Callable[..., None]) -> SharedHeartbeatSender: (source)

Register a heartbeat function.

Parameters
task_token:bytesUnique task token for the heartbeater.
heartbeat:Callable[..., None]Function that should be called when the resulting sender is sent a heartbeat.
Returns
SharedHeartbeatSenderA sender that can be pickled for use in another process.
@abstractmethod
async def unregister_heartbeater(self, task_token: bytes): (source)

Unregisters a previously registered heartbeater for the task token. This should also flush any pending heartbeats.