def initialize(self): self._conn_info = [] if self._mode == 'tcp': port = self._frsock.bind_to_random_port('tcp://*') self._conn_info.append('tcp://{}:{}'.format(get_addr(), port)) port = self._tosock.bind_to_random_port('tcp://*') self._conn_info.append('tcp://{}:{}'.format(get_addr(), port)) elif self._mode == 'ipc': self._conn_info.append(bind_to_random_ipc(self._frsock, self._name + '-c2s-')) self._conn_info.append(bind_to_random_ipc(self._tosock, self._name + '-s2c-')) self._rcv_thread = threading.Thread(target=self.mainloop_recv, daemon=True) self._rcv_thread.start() self._snd_thread = threading.Thread(target=self.mainloop_send, daemon=True) self._snd_thread.start()
def initialize(self): if self._conn_info is not None: return if self._mode == 'tcp': port = self._sock.bind_to_random_port('tcp://*') self._conn_info = 'tcp://{}:{}'.format(get_addr(), port) elif self._mode == 'ipc': self._conn_info = bind_to_random_ipc(self._sock, self._name)
def initialize(self): if self._conn_info is not None: return if self._mode == 'tcp': port = self._sock.bind_to_random_port('tcp://*') self._conn_info = 'tcp://{}:{}'.format(get_addr(), port) elif self._mode == 'ipc': self._conn_info = bind_to_random_ipc(self._sock, self._name) self._send_queue = queue.Queue(maxsize=self._send_qsize) self._send_thread = threading.Thread(target=self.mainloop_send, daemon=True) self._send_thread.start()
def __init__(self): self._uid = utils.uid() self._addr = utils.get_addr() # pipes of this controller self._imanager = ControllerPipeStorage() self._omanager = ControllerPipeStorage() # context and poller self._context = zmq.Context() self._context.sndhwm = _configs.CTL_CTL_HWM self._context.rcvhwm = _configs.CTL_CTL_HWM # socket pools self._ns_socket = None # control router and dispatcher self._control_router = None self._control_router_port = 0 self._control_dispatcher = CallbackRegistry() # queue of ControlMessage self._control_mqueue = queue.Queue() self._control_poller = zmq.Poller() # peers respect to the controller # map uid => ControllerPeer self._controller_peers = dict() # the peers of input pipes (i.e. the output pipes) self._input_from = dict() self._input_cache = dict() self._output_to = dict() self._output_to_pipe = collections.defaultdict( dict) # the peers of output pipes self._output_to_id = dict() self._output_cache = dict() # map pipe_name => cache self._data_poller = zmq.Poller() # threads and stop-event self._all_socks = set() self._all_threads = [] self._stop_event = threading.Event()