eventloop.future#

Module: eventloop.future#

Future-returning APIs for tornado coroutines.

See also

zmq.asyncio

New in version 15.0.

As of pyzmq 15, there is a new Socket subclass that returns Futures for recv methods, which can be found at zmq.eventloop.future.Socket. You can create these sockets by instantiating a Context from the same module. These sockets let you easily use zmq with tornado’s coroutines.

See also

tornado.gen

from tornado import gen
from zmq.eventloop.future import Context

ctx = Context()

@gen.coroutine
def recv_and_process():
    sock = ctx.socket(zmq.PULL)
    sock.bind(url)
    msg = yield sock.recv_multipart() # waits for msg to be ready
    reply = yield async_process(msg)
    yield sock.send_multipart(reply)

Classes#

Context#

Context class that creates Future-returning sockets. See zmq.Context for more info.

class zmq.eventloop.future.Context(*args: Any, **kwargs: Any)

Socket#

Socket subclass that returns Future s from blocking methods, for use in coroutines and async applications.

See also

zmq.Socket for the inherited API.

class zmq.eventloop.future.Socket(context=None, socket_type=-1, io_loop=None, _from_socket: Socket | None = None, **kwargs)
recv(flags: int = 0, copy: bool = True, track: bool = False) Awaitable[bytes | Frame]

Receive a single zmq frame.

Returns a Future, whose result will be the received frame.

Recommend using recv_multipart instead.

recv_multipart(flags: int = 0, copy: bool = True, track: bool = False) Awaitable[List[bytes] | List[Frame]]

Receive a complete multipart zmq message.

Returns a Future whose result will be a multipart message.

send(data: Any, flags: int = 0, copy: bool = True, track: bool = False, **kwargs: Any) Awaitable[MessageTracker | None]

Send a single zmq frame.

Returns a Future that resolves when sending is complete.

Recommend using send_multipart instead.

send_multipart(msg_parts: Any, flags: int = 0, copy: bool = True, track=False, **kwargs) Awaitable[MessageTracker | None]

Send a complete multipart zmq message.

Returns a Future that resolves when sending is complete.

poll(timeout=None, flags=PollEvent.POLLIN) Awaitable[int]

poll the socket for events

returns a Future for the poll results.

Poller#

Poller subclass that returns Future s from poll, for use in coroutines and async applications.

See also

zmq.Poller for the inherited API.

class zmq.eventloop.future.Poller
poll(timeout=-1) Awaitable[List[Tuple[Any, int]]]

Return a Future for a poll event