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 three 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
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
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
x.__delattr__(‘name’) <==> del x.name
default object formatter
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
__sizeof__() -> int size of object in memory, in bytes
x.__str__() <==> str(x)
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: |
|
---|---|
Returns: | int |
Return type: | count of events handled (both send and recv) |
DEPRECATED, does nothing
Register a callback for 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.
Use on_recv_stream(callback) instead, to register a callback that will receive both this ZMQStream and the message, instead of just the message.
Parameters: |
|
---|
Same as on_recv, but callback will get this stream as first argument
callback must take exactly two arguments, as it will be called as:
callback(stream, msg)
Useful when a single callback should be used with multiple streams.
Register a callback to be called on each send
There will be two arguments:
callback(msg, status)
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.
Use on_send_stream(callback) to register a callback that will be passed this ZMQStream as the first argument, in addition to the other two.
on_send(None) disables recv event polling.
Parameters: | callback (callable) – callback must take exactly two arguments, which will be the message being sent (always a list), and the return result of socket.send_multipart(msg) - MessageTracker or None. if callback is None, send callbacks are disabled. |
---|
Same as on_send, but callback will get this stream as first argument
Callback will be passed three arguments:
callback(stream, msg, status)
Useful when a single callback should be used with multiple streams.
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.
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.
DEPRECATED, does nothing
Disable callback and automatic receiving.
Disable callback on sending.