loop

class EventloopMixin[source]

Mixin to provide common asyncio zmq scaffolding to networked classes.

Inheriting classes should, in order

  • call the _init_loop method to create the eventloop, context, and poller

  • populate the private _sockets and _receivers dicts

  • await the _poll_sockets method, which polls indefinitely.

Inheriting classes must ensure that _init_loop is called in the thread it is intended to run in, and that thread must already have a running eventloop. asyncio eventloops (and most of asyncio) are not thread safe.

To help avoid cross-threading issues, the context() and loop() properties do not automatically create the objects, raising a RuntimeError if they are accessed before _init_loop is called.

property context: Context
property loop: AbstractEventLoop
property sockets: dict[str, Socket]
register_socket(name: str, socket: Socket, receiver: bool = False) None[source]

Register a socket, optionally declaring it as a receiver socket to poll

add_callback(socket: str, callback: Callable[[Message], Any] | Callable[[Message], Coroutine]) None[source]

Add a callback to be called when the socket receives a message. Callbacks are called in the order in which they are added.

clear_callbacks() None[source]