async def _send_request(self, request_type, payload): """Uses an executor to send an asynchronous ZMQ request to the validator with the handler's Stream. """ future = self._stream.send(message_type=request_type, content=payload) try: return await self._loop.run_in_executor( None, future.result, self._timeout) except FutureTimeoutError: LOGGER.warning('Timed out while waiting for validator response') raise errors.ValidatorTimedOut()
async def _send_request(self, request_type, payload): """Uses an executor to send an asynchronous ZMQ request to the validator with the handler's Connection """ try: return await self._connection.send(message_type=request_type, message_content=payload, timeout=self._timeout) except DisconnectError: LOGGER.warning('Validator disconnected while waiting for response') raise errors.ValidatorDisconnected() except asyncio.TimeoutError: LOGGER.warning('Timed out while waiting for validator response') raise errors.ValidatorTimedOut()
async def _try_validator_request(self, message_type, content): """Serializes and sends a Protobuf message to the validator. Handles timeout errors as needed. """ if isinstance(content, BaseMessage): content = content.SerializeToString() future = self._stream.send(message_type=message_type, content=content) try: response = await self._loop.run_in_executor( None, future.result, self._timeout) except FutureTimeoutError: raise errors.ValidatorTimedOut() try: return response.content except ValidatorConnectionError: raise errors.ValidatorDisconnected()