File: //lib64/python3.6/site-packages/zmq/devices/__pycache__/basedevice.cpython-36.opt-1.pyc
3
VS�_! � @ s� d Z ddlZddlmZ ddlmZ ddlmZmZm Z m
Z
mZmZm
Z
G dd� d�ZG dd � d e�ZG d
d� de�ZG dd
� d
e�Zddd
gZdS )z2Classes for running 0MQ Devices in the background.� N)�Thread)�Process)�device�QUEUE�REQ�Context�ETERM�ZMQBindError�ZMQErrorc @ s� e Zd ZdZejZeddfdd�Zdd� Z dd� Z
d d
� Zdd� Zd
d� Z
dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd!dd �ZdS )"�Deviceac 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
----------
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.
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
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.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.
Nc C sl || _ |d krtd��|d kr&td��|| _|| _g | _g | _g | _g | _g | _g | _ g | _
d| _d| _d S )Nzin_type must be specifiedzout_type must be specifiedTF)
�device_type� TypeError�in_type�out_type� _in_binds�_in_connects�_in_sockopts�
_out_binds�
_out_connects�
_out_sockopts�
_random_addrs�daemon�done)�selfr r r � r �"/usr/lib64/python3.6/basedevice.py�__init__F s zDevice.__init__c C s | j j|� dS )z`Enqueue ZMQ address for binding on in_socket.
See zmq.Socket.bind for details.
N)r �append)r �addrr r r �bind_inX s zDevice.bind_inc O s( | j |f|�|�}| jd||f � |S )z�Enqueue a random port on the given interface for binding on
in_socket.
See zmq.Socket.bind_to_random_port for details.
.. versionadded:: 18.0
z%s:%i)�_reserve_random_portr )r r �args�kwargs�portr r r �bind_in_to_random_port_ s zDevice.bind_in_to_random_portc C s | j j|� dS )zfEnqueue ZMQ address for connecting on in_socket.
See zmq.Socket.connect for details.
N)r r )r r r r r �
connect_inm s zDevice.connect_inc C s | j j||f� dS )zeEnqueue setsockopt(opt, value) for in_socket
See zmq.Socket.setsockopt for details.
N)r r )r �opt�valuer r r �
setsockopt_int s zDevice.setsockopt_inc C s | j j|� dS )zaEnqueue ZMQ address for binding on out_socket.
See zmq.Socket.bind for details.
N)r r )r r r r r �bind_out{ s zDevice.bind_outc O s( | j |f|�|�}| jd||f � |S )z�Enqueue a random port on the given interface for binding on
out_socket.
See zmq.Socket.bind_to_random_port for details.
.. versionadded:: 18.0
z%s:%i)r r) )r r r! r"