devices¶
Functions¶
-
zmq.
device
(device_type, frontend, backend) Start a zeromq device.
Deprecated since version libzmq-3.2: Use zmq.proxy
Parameters:
-
zmq.
proxy
(frontend, backend, capture) Start a zeromq proxy (replacement for device).
New in version libzmq-3.2.
New in version 13.0.
Parameters:
Module: zmq.devices
¶
0MQ Device classes for running in background threads or processes.
Base Devices¶
Device
¶
-
class
zmq.devices.
Device
(device_type=3, in_type=None, out_type=None)¶ A 0MQ Device to be run in the background.
You do not pass Socket instances to this, but rather Socket types:
Device(device_type, in_socket_type, out_socket_type)
For instance:
dev = Device(zmq.QUEUE, zmq.DEALER, zmq.ROUTER)
Similar to zmq.device, but socket types instead of sockets themselves are passed, and the sockets are created in the work thread, to avoid issues with thread safety. As a result, additional bind_{in|out} and connect_{in|out} methods and setsockopt_{in|out} allow users to specify connections for the sockets.
Parameters: -
bind_{in_out}(iface)
passthrough for
{in|out}_socket.bind(iface)
, to be called in the thread
-
connect_{in_out}(iface)
passthrough for
{in|out}_socket.connect(iface)
, to be called in the thread
-
setsockopt_{in_out}(opt,value)
passthrough for
{in|out}_socket.setsockopt(opt, value)
, to be called in the thread
-
daemon
¶ int – sets whether the thread should be run as a daemon Default is true, because if it is false, the thread will not exit unless it is killed
-
context_factory
¶ callable (class attribute) – Function for creating the Context. This will be Context.instance in ThreadDevices, and Context in ProcessDevices. The only reason it is not instance() in ProcessDevices is that there may be a stale Context instance already initialized, and the forked environment should never try to use it.
-
bind_in
(addr)¶ Enqueue ZMQ address for binding on in_socket.
See zmq.Socket.bind for details.
-
bind_out
(addr)¶ Enqueue ZMQ address for binding on out_socket.
See zmq.Socket.bind for details.
-
connect_in
(addr)¶ Enqueue ZMQ address for connecting on in_socket.
See zmq.Socket.connect for details.
-
connect_out
(addr)¶ Enqueue ZMQ address for connecting on out_socket.
See zmq.Socket.connect for details.
-
join
(timeout=None)¶ wait for me to finish, like Thread.join.
Reimplemented appropriately by subclasses.
-
setsockopt_in
(opt, value)¶ Enqueue setsockopt(opt, value) for in_socket
See zmq.Socket.setsockopt for details.
-
setsockopt_out
(opt, value)¶ Enqueue setsockopt(opt, value) for out_socket
See zmq.Socket.setsockopt for details.
-
start
()¶ Start the device. Override me in subclass for other launchers.
-
ThreadDevice
¶
-
class
zmq.devices.
ThreadDevice
(device_type=3, in_type=None, out_type=None)¶ A Device that will be run in a background Thread.
See Device for details.
Proxy Devices¶
Proxy
¶
-
class
zmq.devices.
Proxy
(in_type, out_type, mon_type=1)¶ Threadsafe Proxy object.
See zmq.devices.Device for most of the spec. This subclass adds a <method>_mon version of each <method>_{in|out} method, for configuring the monitor socket.
A Proxy is a 3-socket ZMQ Device that functions just like a QUEUE, except each message is also sent out on the monitor socket.
A PUB socket is the most logical choice for the mon_socket, but it is not required.
-
bind_mon
(addr)¶ Enqueue ZMQ address for binding on mon_socket.
See zmq.Socket.bind for details.
-
connect_mon
(addr)¶ Enqueue ZMQ address for connecting on mon_socket.
See zmq.Socket.bind for details.
-
setsockopt_mon
(opt, value)¶ Enqueue setsockopt(opt, value) for mon_socket
See zmq.Socket.setsockopt for details.
-
ThreadProxy
¶
-
class
zmq.devices.
ThreadProxy
(in_type, out_type, mon_type=1)¶ Proxy in a Thread. See Proxy for more.
ProcessProxy
¶
-
class
zmq.devices.
ProcessProxy
(in_type, out_type, mon_type=1)¶ Proxy in a Process. See Proxy for more.
MonitoredQueue Devices¶
-
zmq.devices.
monitored_queue
()¶ - monitored_queue(in_socket, out_socket, mon_socket,
- in_prefix=b’in’, out_prefix=b’out’)
Start a monitored queue device.
A monitored queue is very similar to the zmq.proxy device (monitored queue came first).
Differences from zmq.proxy:
- monitored_queue supports both in and out being ROUTER sockets (via swapping IDENTITY prefixes).
- monitor messages are prefixed, making in and out messages distinguishable.
Parameters: - in_socket (Socket) – One of the sockets to the Queue. Its messages will be prefixed with ‘in’.
- out_socket (Socket) – One of the sockets to the Queue. Its messages will be prefixed with ‘out’. The only difference between in/out socket is this prefix.
- mon_socket (Socket) – This socket sends out every message received by each of the others with an in/out prefix specifying which one it was.
- in_prefix (str) – Prefix added to broadcast messages from in_socket.
- out_prefix (str) – Prefix added to broadcast messages from out_socket.
MonitoredQueue
¶
-
class
zmq.devices.
MonitoredQueue
(in_type, out_type, mon_type=1, in_prefix=b'in', out_prefix=b'out')¶ Class for running monitored_queue in the background.
See zmq.devices.Device for most of the spec. MonitoredQueue differs from Proxy, only in that it adds a
prefix
to messages sent on the monitor socket, with a different prefix for each direction.MQ also supports ROUTER on both sides, which zmq.proxy does not.
If a message arrives on in_sock, it will be prefixed with in_prefix on the monitor socket. If it arrives on out_sock, it will be prefixed with out_prefix.
A PUB socket is the most logical choice for the mon_socket, but it is not required.
ThreadMonitoredQueue
¶
-
class
zmq.devices.
ThreadMonitoredQueue
(in_type, out_type, mon_type=1, in_prefix=b'in', out_prefix=b'out')¶ Run zmq.monitored_queue in a background thread.
See MonitoredQueue and Proxy for details.
ProcessMonitoredQueue
¶
-
class
zmq.devices.
ProcessMonitoredQueue
(in_type, out_type, mon_type=1, in_prefix=b'in', out_prefix=b'out')¶ Run zmq.monitored_queue in a background thread.
See MonitoredQueue and Proxy for details.