Exemplo n.º 1
0
 def _setup_comms(self, icomm_name, icomm_kwargs, ocomm_name, ocomm_kwargs):
     r"""Set up input/output comms."""
     try:
         self.icomm = get_comm(icomm_name, **icomm_kwargs)
         self.ocomm = get_comm(ocomm_name, **ocomm_kwargs)
     except BaseException:
         self.close(skip_base=True)
         raise
Exemplo n.º 2
0
 def __init__(self,
              name,
              request_comm=None,
              response_kwargs=None,
              dont_open=False,
              **kwargs):
     if response_kwargs is None:
         response_kwargs = dict()
     icomm_name = name
     icomm_kwargs = kwargs
     icomm_kwargs['direction'] = 'recv'
     icomm_kwargs['dont_open'] = True
     icomm_kwargs['comm'] = request_comm
     self.response_kwargs = response_kwargs
     self.icomm = get_comm(icomm_name, **icomm_kwargs)
     self.ocomm = None
     self.response_kwargs.setdefault('comm', self.icomm.comm_class)
     self.response_kwargs.setdefault('recv_timeout',
                                     self.icomm.recv_timeout)
     self._used_response_comms = dict()
     super(ServerComm, self).__init__(self.icomm.name,
                                      dont_open=dont_open,
                                      recv_timeout=self.icomm.recv_timeout,
                                      is_interface=self.icomm.is_interface,
                                      direction='recv',
                                      no_suffix=True,
                                      address=self.icomm.address)
Exemplo n.º 3
0
 def __init__(self, name, comm=None, **kwargs):
     self.comm_list = []
     self.curr_comm_index = 0
     self.eof_recv = []
     address = kwargs.pop('address', None)
     if (comm in [None, 'ForkComm']):
         if isinstance(address, list):
             ncomm = len(address)
         else:
             ncomm = 0
         comm = [None for i in range(ncomm)]
     assert (isinstance(comm, list))
     ncomm = len(comm)
     for i in range(ncomm):
         if comm[i] is None:
             comm[i] = {}
         if comm[i].get('name', None) is None:
             comm[i]['name'] = get_comm_name(name, i)
     if isinstance(address, list):
         assert (len(address) == ncomm)
         for i in range(ncomm):
             comm[i]['address'] = address[i]
     for i in range(ncomm):
         ikw = dict(**kwargs)
         ikw.update(**comm[i])
         iname = ikw.pop('name')
         self.comm_list.append(get_comm(iname, **ikw))
         self.eof_recv.append(0)
     if ncomm > 0:
         kwargs['address'] = [x.address for x in self.comm_list]
     kwargs['comm'] = 'ForkComm'
     super(ForkComm, self).__init__(name, **kwargs)
     assert (not self.single_use)
     assert (not self.is_server)
     assert (not self.is_client)
Exemplo n.º 4
0
 def __init__(self,
              name,
              request_comm=None,
              response_kwargs=None,
              dont_open=False,
              **kwargs):
     if response_kwargs is None:
         response_kwargs = dict()
     ocomm_name = name
     ocomm_kwargs = kwargs
     ocomm_kwargs['direction'] = 'send'
     ocomm_kwargs['dont_open'] = True
     ocomm_kwargs['comm'] = request_comm
     self.response_kwargs = response_kwargs
     self.ocomm = get_comm(ocomm_name, **ocomm_kwargs)
     self.icomm = dict()
     self.icomm_order = []
     self.response_kwargs.setdefault('comm', self.ocomm.comm_class)
     self.response_kwargs.setdefault('recv_timeout',
                                     self.ocomm.recv_timeout)
     super(ClientComm, self).__init__(self.ocomm.name,
                                      dont_open=dont_open,
                                      recv_timeout=self.ocomm.recv_timeout,
                                      is_interface=self.ocomm.is_interface,
                                      direction='send',
                                      no_suffix=True,
                                      address=self.ocomm.address)
Exemplo n.º 5
0
 def create_response_comm(self):
     r"""Create a response comm based on information from the last header."""
     if not isinstance(self.icomm._last_header, dict):  # pragma: debug
         raise RuntimeError("No header received with last message.")
     elif 'response_address' not in self.icomm._last_header:  # pragma: debug
         raise RuntimeError("Last header does not contain response address.")
     comm_kwargs = dict(address=self.icomm._last_header['response_address'],
                        direction='send', is_response_server=True,
                        single_use=True, **self.response_kwargs)
     self.ocomm = get_comm(self.name + '.server_response_comm',
                           **comm_kwargs)
Exemplo n.º 6
0
 def create_instance(self):
     r"""Create a new instance of the class."""
     inst = get_comm(*self.inst_args, **self.inst_kwargs)
     assert (isinstance(inst, self.import_cls))
     return inst