eventlet.green.zmq – ØMQ support

The zmq module wraps the Socket and Context found in pyzmq to be non blocking

eventlet.green.zmq.Context(io_threads=1)

Subclass of zmq.core.context.Context

class eventlet.green.zmq.Socket(context, socket_type)

Bases: zmq.sugar.socket.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 recieving is deferred to the hub (using eventlet.hubs.trampoline()) if a zmq.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.

flags : int
Any supported flag: NOBLOCK. If NOBLOCK is set, this method will raise a ZMQError with EAGAIN if a message is not ready. If NOBLOCK is not set, then this method will block until a message arrives.
copy : bool
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.
track : bool
Should the message be tracked for notification that ZMQ has finished with it? (ignored if copy=True)
msg : bytes, Frame
The received message frame. If copy is False, then it will be a Frame, otherwise it will be bytes.
ZMQError
for any of the reasons zmq_msg_recv might fail.
send(data, flags=0, copy=True, track=False)

Send a message on this socket.

This queues the message to be sent by the IO thread at a later time.

data : object, str, Frame
The content of the message.
flags : int
Any supported flag: NOBLOCK, SNDMORE.
copy : bool
Should the message be sent in a copying or non-copying manner.
track : bool
Should the message be tracked for notification that ZMQ has finished with it? (ignored if copy=True)
None : if copy or not track
None if message was sent, raises an exception otherwise.
MessageTracker : if track and not copy
a MessageTracker object, whose pending property will be True until the send is completed.
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.

zmq – The pyzmq ØMQ python bindings

pyzmq [1] Is a python binding to the C++ ØMQ [2] library written in Cython [3]. The following is auto generated pyzmq's from documentation.

class zmq.core.context.Context

Context(io_threads=1)

Manage the lifecycle of a 0MQ context.

io_threads : int
The number of IO threads.
destroy(linger=None)

Close all sockets associated with this context, and then terminate the context. If linger is specified, the LINGER sockopt of the sockets will be set prior to closing.

WARNING:

destroy involves calling zmq_close(), which is NOT threadsafe. If there are active sockets in other threads, this must not be called.

get(option)

Get the value of a context option.

See the 0MQ API documentation for zmq_ctx_get for details on specific options.

New in libzmq-3.2

option : int

The option to get. Available values will depend on your version of libzmq. Examples include:

zmq.IO_THREADS, zmq.MAX_SOCKETS
optval : int
The value of the option as an integer.
set(option, optval)

Set context options.

See the 0MQ API documentation for zmq_ctx_set for details on specific options.

New in libzmq-3.2

option : int

The option to set. Available values will depend on your version of libzmq. Examples include:

zmq.IO_THREADS, zmq.MAX_SOCKETS
optval : int
The value of the option to set.
term()

Close or terminate the context.

This can be called to close the context by hand. If this is not called, the context will automatically be closed when it is garbage collected.

class zmq.core.socket.Socket

Socket(context, socket_type)

A 0MQ socket.

These objects will generally be constructed via the socket() method of a Context object.

Note: 0MQ Sockets are not threadsafe. DO NOT share them across threads.

context : Context
The 0MQ Context this Socket belongs to.
socket_type : int
The socket type, which can be any of the 0MQ socket types: REQ, REP, PUB, SUB, PAIR, DEALER, ROUTER, PULL, PUSH, XPUB, XSUB.

.Context.socket : method for creating a socket bound to a Context.

[1]http://github.com/zeromq/pyzmq
[2]http://www.zeromq.com
[3]http://www.cython.org

Table Of Contents

Previous topic

wsgi – WSGI server

Next topic

Authors

This Page