eventlet.green.zmq
– ØMQ support¶
pyzmq
[1] is a python binding to the C++ ØMQ [2] library written in Cython [3].
eventlet.green.zmq
is greenthread aware version of pyzmq.
The zmq
module wraps the Socket
and Context
found in pyzmq
to be non blocking.
- class eventlet.green.zmq.Context(io_threads: int = 1, **kwargs: Any)¶
Bases:
Context
Subclass of
zmq.Context
- class eventlet.green.zmq.Socket(context, socket_type)¶
Bases:
Socket
Green version of :class:`zmq.core.socket.Socket
- The following three methods are always overridden:
send
recv
getsockopt
To ensure that the
zmq.NOBLOCK
flag is set and that sending or receiving is deferred to the hub (usingeventlet.hubs.trampoline()
) if azmq.EAGAIN
(retry) error is raised- For some socket types, the following methods are also overridden:
send_multipart
recv_multipart
- recv(flags=0, copy=True, track=False)¶
Receive a message.
With flags=NOBLOCK, this raises
ZMQError
if no messages have arrived; otherwise, this waits until a message arrives. SeePoller
for more general non-blocking I/O.Parameters¶
- flagsint
0 or NOBLOCK.
- copybool
Should the message be received in a copying or non-copying manner? If False a Frame object is returned, if True a string copy of message is returned.
- trackbool
Should the message be tracked for notification that ZMQ has finished with it? (ignored if copy=True)
Returns¶
- msgbytes or Frame
The received message frame. If copy is False, then it will be a Frame, otherwise it will be bytes.
Raises¶
- ZMQError
for any of the reasons zmq_msg_recv might fail (including if NOBLOCK is set and no new messages have arrived).
- send(msg, flags=0, copy=True, track=False)¶
Send a single zmq message frame on this socket.
This queues the message to be sent by the IO thread at a later time.
With flags=NOBLOCK, this raises
ZMQError
if the queue is full; otherwise, this waits until space is available. SeePoller
for more general non-blocking I/O.Parameters¶
- databytes, Frame, memoryview
The content of the message. This can be any object that provides the Python buffer API (i.e. memoryview(data) can be called).
- flagsint
0, NOBLOCK, SNDMORE, or NOBLOCK|SNDMORE.
- copybool
Should the message be sent in a copying or non-copying manner.
- trackbool
Should the message be tracked for notification that ZMQ has finished with it? (ignored if copy=True)
- routing_idint
For use with SERVER sockets
- groupstr
For use with RADIO sockets
Returns¶
- Noneif copy or not track
None if message was sent, raises an exception otherwise.
- MessageTrackerif track and not copy
a MessageTracker object, whose pending property will be True until the send is completed.
Raises¶
- TypeError
If a unicode object is passed
- ValueError
If track=True, but an untracked Frame is passed.
- ZMQError
If the send does not succeed for any reason (including if NOBLOCK is set and the outgoing queue is full).
Changed in version 17.0: DRAFT support for routing_id and group arguments.