loop¶
- class EventloopMixin[source]¶
Mixin to provide common asyncio zmq scaffolding to networked classes.
Inheriting classes should, in order
call the
_init_loopmethod to create the eventloop, context, and pollerpopulate the private
_socketsand_receiversdictsawait the
_poll_socketsmethod, which polls indefinitely.
Inheriting classes must ensure that
_init_loopis 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()andloop()properties do not automatically create the objects, raising aRuntimeErrorif they are accessed before_init_loopis called.To handle slow subscribers in PUB/SUB, use an XPUB instead, and each subscriber also subscribes to a topic with the
SUBSCRIBER_PREFIX:id. The XPUB then polls for receive events with _poll_subscriptions, and maintains a list of nodes that have subscribed to it. Subscribers can then wait for the publisher to acknowledge its subscription before marking themselves as ready.- property context: Context¶
- property loop: AbstractEventLoop¶
- register_socket(name: str, socket: Socket, receiver: bool = False) None[source]¶
Register a socket, optionally declaring it as a receiver socket to poll