pyams_zmq package ⊞

PyAMS_zmq package

This package provides features to enable local or remote inter-processes communication using the 0MQ protocol and the PyZMQ package.

Several PyAMS packages rely on this package to provide asynchronous handling of long operations like medias conversions, Elasticsearch indexing or communication with the tasks scheduler.


Pyramid include


PyAMS_zmq.handler module

This module provides a default implementation of a 0MQ messages handler.

These handlers are simple classes which delegate the real message handling to their “handler” attribute, which is a simple class which may have a method matching the message type.

class pyams_zmq.handler.ZMQMessageHandler(process, stream, stop, handler=None, json_load=-1)[source]

Bases: object

Base class for message handlers for a pyams_zmq.process.Process.

Inheriting classes only need to implement a handler function for each message type.

handler = None


PyAMS_zmq.process module

A 0MQ process is a “classic” Python subprocess, which is starting a 0MQ event loop on startup to be able to handle incoming connections.

To each process is attached a messages handler, which is responsible of doing the concrete messages handling.

Process initialization arguments allows to define a list of client IP addresses which are allowed to connect to this process, as well as a login/password authentication tokens which must be provided to connect to this process.

class pyams_zmq.process.ZMQProcess(bind_addr, handler, auth=None, clients=None)[source]

Bases: multiprocessing.context.Process

This is the base for all processes and offers utility methods for setup and creating new streams.

auth_thread = None
context = None

The ØMQ Context instance.

exit(num, frame)[source]

Process exit


Initialize response stream

loop = None

PyZMQ’s event loop (IOLoop).


Sets up everything and starts the event loop on process startup


Creates a context and an event loop for the process.

socket_type = 4

Stops the event loop.

stream(sock_type, addr, bind, callback=None, subscribe=b'')[source]

Creates a ZMQStream.

  • sock_type – The ØMQ socket type (e.g. zmq.REQ)
  • addr

    Address to bind or connect to formatted as host:port, (host, port) or host (bind to random port). If bind is True, host may be:

    • the wild-card *, meaning all available interfaces,
    • the primary IPv4 address assigned to the interface, in its

    numeric representation or - the interface name as defined by the operating system.

    If bind is False, host may be:

    • the DNS name of the peer or
    • the IPv4 address of the peer, in its numeric representation.

    If addr is just a host name without a port and bind is True, the socket will be bound to a random port.

  • bind – Binds to addr if True or tries to connect to it otherwise.
  • callback – A callback for on_recv(), optional
  • subscribe – Subscription pattern for SUB sockets, optional, defaults to b''.

A tuple containg the stream and the port number.


Process exit func is required to correctly end the child process


PyAMS_zmq.socket module

This module provides a few helpers which can be used to open a 0MQ socket and handle response.

pyams_zmq.socket.zmq_response(socket, flags=1, timeout=10)[source]

Get response from given socket

pyams_zmq.socket.zmq_socket(address, socket_type=3, linger=0, protocol='tcp', auth=None)[source]

Get ØMQ socket

auth is given as unicode ‘username:password’ string and automatically converted to bytes.