def test_client_server_eventloop(): host = '127.0.0.1' port = 7001 N = 20 data = [None, None] server = ZmqServer(host=host, port=port, serializer='pickle', deserializer='pickle') all_requests = [] def handler(x): if x == N - 1: server.stop() all_requests.append(x) return x + 1 server_thread = server.start_loop(handler, blocking=False) client = ZmqClient(host=host, port=port, serializer='pickle', deserializer='pickle') all_responses = [] for i in range(N): all_responses.append(client.request(i)) data[1] = all_responses server_thread.join() assert all_requests == [n for n in range(N)] assert all_responses == [n + 1 for n in range(N)]
def __init__( self, host, port, agent_scope, timeout=2, not_ready_sleep=2, ): """ Args: host: parameter server host port: parameter server port timeout: how long should the the client wait if the parameter server is not available """ self.host = host self.port = port self.timeout = timeout self._current_info = {} self._last_hash = '' self.alive = False self._agent_scope = agent_scope self._not_ready_sleep = not_ready_sleep self._client = ZmqClient(host=self.host, port=self.port, timeout=self.timeout, serializer=U.serialize, deserializer=U.deserialize)
def client_fn(): cli = ZmqClient(host=args.ip, port=args.port, timeout=args.timeout, serializer='pyarrow', deserializer='pyarrow') cli.request(MSG) print('Done')
def client(N): client = ZmqClient(host=host, port=port, serializer='pickle', deserializer='pickle') all_responses = [] for i in range(N): all_responses.append(client.request(i)) data[1] = all_responses
def client(): client = ZmqClient(host=host, port=port, timeout=0.3, serializer='pickle', deserializer='pickle') assert client.request('request-1') == 'received-request-1' with pytest.raises(ZmqTimeoutError): client.request('request-2') assert client.request('request-3') == 'received-request-3'
def get_irs_client(timeout, auto_detect_proxy=True): if 'SYMPH_IRS_PROXY_HOST' in os.environ and auto_detect_proxy: host = os.environ['SYMPH_IRS_PROXY_HOST'] port = os.environ['SYMPH_IRS_PROXY_PORT'] else: host = os.environ['SYMPH_IRS_HOST'] port = os.environ['SYMPH_IRS_PORT'] return ZmqClient(host=host, port=port, serializer='pyarrow', deserializer='pyarrow', timeout=timeout)
def __init__(self, host, port, agent_scope): """ Args: host: IP of the ps port: the port connected to the pub socket """ self._agent_scope = agent_scope self.alive = False self._publisher = ZmqClient( host=host, port=port, timeout=2, serializer=U.serialize, deserializer=U.deserialize, )
def _setup_spec_client(self): self.spec_client = ZmqClient(host=os.environ['SYMPH_SPEC_HOST'], port=os.environ['SYMPH_SPEC_PORT'], serializer=U.pickle_serialize, deserializer=U.pickle_deserialize, timeout=4)
def _register_commands_with_irs(self, commands, host, port): self._cli = ZmqClient(host=host, port=port, serializer='pyarrow', deserializer='pyarrow') self._cli.request(['register_commands', [], commands])