eventloop.future#
Module: zmq.eventloop.future
#
Future-returning APIs for tornado coroutines.
See also
Added 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 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
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.
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.
Poller
#
Poller subclass that returns Future
s from poll,
for use in coroutines and async applications.
See also
zmq.Poller
for the inherited API.