执行远程调用获取数据 :param host: :param request_param: :param timeout: :return:
(self, host, request_param, timeout=None)
| 38 | scanning_thread.start() |
| 39 | |
| 40 | def get(self, host, request_param, timeout=None): |
| 41 | """ |
| 42 | 执行远程调用获取数据 |
| 43 | :param host: |
| 44 | :param request_param: |
| 45 | :param timeout: |
| 46 | :return: |
| 47 | """ |
| 48 | conn = self._get_connection(host) |
| 49 | request = Request(request_param) |
| 50 | request_data = request.encode() |
| 51 | invoke_id = request.invoke_id |
| 52 | |
| 53 | event = threading.Event() |
| 54 | self.conn_events[invoke_id] = event |
| 55 | # 发送数据 |
| 56 | conn.write(request_data) |
| 57 | logger.debug('Waiting response, invoke_id={}, timeout={}, host={}'.format(invoke_id, timeout, host)) |
| 58 | event.wait(timeout) |
| 59 | del self.conn_events[invoke_id] |
| 60 | |
| 61 | if invoke_id not in self.results: |
| 62 | err = "Socket(host='{}'): Read timed out. (read timeout={})".format(host, timeout) |
| 63 | raise DubboRequestTimeoutException(err) |
| 64 | |
| 65 | result = self.results.pop(invoke_id) |
| 66 | if isinstance(result, Exception): |
| 67 | logger.exception(result) |
| 68 | logger.error('Exception {} for host {}'.format(result, host)) |
| 69 | raise result |
| 70 | return result |
| 71 | |
| 72 | def _get_connection(self, host): |
| 73 | """ |
no test coverage detected