A utility class to send to and recv from a non-blocking socket.
A utility class to register callbacks when a zmq socket sends and receives
For use with zmq.eventloop.ioloop
There are 4 main methods
Methods:
register a callback to be run every time the socket has something to receive
register a callback to be run every time you call send
register a callback to be run every time there is an error
perform a send that will trigger the callback if callback is passed, on_send is also called
There are also send_multipart(), send_json(), send_pyobj()
Three other methods for deactivating the callbacks:
turn off the recv callback
turn off the send callback
turn off the error callback
All of which simply call on_<evt>(None).
The entire socket interface, excluding direct recv methods, is also provided, primarily through direct-linking the methods. e.g.
>>> stream.bind is stream.socket.bind
True
Close this stream.
Flush pending messages.
This method safely handles all pending incoming and/or outgoing messages, bypassing the inner loop, passing them to the registered callbacks.
A limit can be specified, to prevent blocking under high load.
Note that if flag|POLLIN != 0, recv events will be flushed even if no callback is registered, unlike normal IOLoop operation. This allows flush to be used to remove and ignore incoming messages.
Parameters : | flag : int, default=POLLIN|POLLOUT
limit : None or int, optional
|
---|---|
Returns : | int : count of events handled (both send and recv) |
register a callback to be called on POLLERR events with no arguments.
Parameters : | callback : callable
|
---|
Register a callback to be called when a message is ready to recv. There can be only one callback registered at a time, so each call to on_recv replaces previously registered callbacks.
on_recv(None) disables recv event polling.
Parameters : | callback : callable
copy : bool
Returns : None |
---|
Register a callback to be called on each send There will be two arguments: the message being sent (always a list), and the return result of socket.send_multipart(msg).
Non-copying sends return a MessageTracker object whose done attribute will be True when the send is complete. This allows users to track when an object is safe to write to again.
The second argument will always be None if copy=True on the send.
on_send(None) disables recv event polling.
Parameters : | callback : callable
|
---|
Returns True if we are currently receiving from the stream.
Send a message, optionally also register a new callback for sends. See zmq.socket.send for details.
Send json-serialized version of an object. See zmq.socket.send_json for details.
Send a multipart message, optionally also register a new callback for sends. See zmq.socket.send_multipart for details.
Send a Python object as a message using pickle to serialize.
See zmq.socket.send_json for details.
Send a unicode message with an encoding. See zmq.socket.send_unicode for details.
Returns True if we are currently sending to the stream.
Call the given callback when the stream is closed.
Disable callback on errors.
Disable callback and automatic receiving.
Disable callback on sending.