PyZMQ Documentation

Table Of Contents

Previous topic

core.version

Next topic

devices.monitoredqueuedevice

This Page

devices.basedevice

Module: devices.basedevice

Classes for running 0MQ Devices in the background.

Authors

  • MinRK
  • Brian Granger

Classes

BackgroundDevice

class zmq.devices.basedevice.BackgroundDevice(device_type, in_type, out_type)

Base class for launching Devices in background processes and threads.

bind_in(addr)

Enqueue ZMQ address for binding on in_socket.

See zmq.Socket.bind for details.

bind_out(iface)

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(iface)

Enqueue ZMQ address for connecting on out_socket.

See zmq.Socket.connect for details.

static context_factory()

Returns a global Context instance.

Most single-threaded applications have a single, global Context. Use this method instead of passing around Context instances throughout your code.

A common pattern for classes that depend on Contexts is to use a default argument to enable programs with multiple Contexts but not require the argument for simpler applications:

class MyClass(object):
def __init__(self, context=None):
self.context = context or Context.instance()
join(timeout=None)
launcher = None
run()

The runner method.

Do not call me directly, instead call self.start(), just like a Thread.

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()

Device

class zmq.devices.basedevice.Device(device_type, in_type, out_type)

A Threadsafe 0MQ Device.

Warning as with most ‘threadsafe’ Python objects, this is only threadsafe as long as you do not use private methods or attributes. Private names are prefixed with ‘_’, such as self._setup_socket().

For thread safety, you do not pass Sockets 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 :

device_type : int

The 0MQ Device type

{in|out}_type : int

zmq socket types, to be passed later to context.socket(). e.g. zmq.PUB, zmq.SUB, zmq.REQ. If out_type is < 0, then in_socket is used for both in_socket and out_socket.

Attributes :

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.intance 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.

Methods :

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

bind_in(addr)

Enqueue ZMQ address for binding on in_socket.

See zmq.Socket.bind for details.

bind_out(iface)

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(iface)

Enqueue ZMQ address for connecting on out_socket.

See zmq.Socket.connect for details.

static context_factory()

Returns a global Context instance.

Most single-threaded applications have a single, global Context. Use this method instead of passing around Context instances throughout your code.

A common pattern for classes that depend on Contexts is to use a default argument to enable programs with multiple Contexts but not require the argument for simpler applications:

class MyClass(object):
def __init__(self, context=None):
self.context = context or Context.instance()
join(timeout=None)

wait for me to finish, like Thread.join.

Reimplemented appropriately by sublcasses.

run()

The runner method.

Do not call me directly, instead call self.start(), just like a Thread.

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.

ProcessDevice

class zmq.devices.basedevice.ProcessDevice(device_type, in_type, out_type)

A Device that will be run in a background Process.

See Device for details.

bind_in(addr)

Enqueue ZMQ address for binding on in_socket.

See zmq.Socket.bind for details.

bind_out(iface)

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(iface)

Enqueue ZMQ address for connecting on out_socket.

See zmq.Socket.connect for details.

context_factory

alias of Context

join(timeout=None)
launcher = None
run()

The runner method.

Do not call me directly, instead call self.start(), just like a Thread.

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()

ThreadDevice

class zmq.devices.basedevice.ThreadDevice(device_type, in_type, out_type)

A Device that will be run in a background Thread.

See Device for details.

bind_in(addr)

Enqueue ZMQ address for binding on in_socket.

See zmq.Socket.bind for details.

bind_out(iface)

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(iface)

Enqueue ZMQ address for connecting on out_socket.

See zmq.Socket.connect for details.

static context_factory()

Returns a global Context instance.

Most single-threaded applications have a single, global Context. Use this method instead of passing around Context instances throughout your code.

A common pattern for classes that depend on Contexts is to use a default argument to enable programs with multiple Contexts but not require the argument for simpler applications:

class MyClass(object):
def __init__(self, context=None):
self.context = context or Context.instance()
join(timeout=None)
launcher = None
run()

The runner method.

Do not call me directly, instead call self.start(), just like a Thread.

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()