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.
Subpackages¶
pyams_zmq.handler
¶
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.
pyams_zmq.process
¶
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.
-
loop
= None¶ PyZMQ’s event loop (
IOLoop
).
-
socket_type
= 4¶
-
stream
(sock_type, addr, bind, callback=None, subscribe=b'')[source]¶ Creates a
ZMQStream
.Parameters: - 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. - the wild-card
- 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''
.
Returns: A tuple containg the stream and the port number.
- sock_type – The ØMQ socket type (e.g.
-
pyams_zmq.socket
¶
PyAMS_zmq.socket module
This module provides a few helpers which can be used to open a 0MQ socket and handle response.