async driver: fix incorrect timeout handling

This commit is contained in:
linuswck 2024-03-20 15:24:56 +08:00
parent 67f9e65df8
commit 7f06fc06fd
1 changed files with 9 additions and 13 deletions

View File

@ -625,7 +625,7 @@ class Kirdy:
async def _read_response(self): async def _read_response(self):
try: try:
response = await asyncio.wait_for(self._reader.read(1024), self.timeout) response = await asyncio.wait_for(self._reader.read(1024), self.timeout)
except TimeoutError: except asyncio.exceptions.TimeoutError:
return { return {
"msg_type": "Internal Timeout" "msg_type": "Internal Timeout"
} }
@ -645,12 +645,10 @@ class Kirdy:
self._writer.write(bytes(json.dumps(cmd), "UTF-8")) self._writer.write(bytes(json.dumps(cmd), "UTF-8"))
await self._writer.drain() await self._writer.drain()
response = await self._read_response() response = await self._read_response()
try:
if response["msg_type"] == "Acknowledge": if response["msg_type"] == "Acknowledge":
return response return response
except:
retry += 1 retry += 1
await asyncio.sleep(0.25) await asyncio.sleep(0.1)
raise NoAckRecv raise NoAckRecv
async def _send_cmd_handler(self, target, cmd, data=None): async def _send_cmd_handler(self, target, cmd, data=None):
@ -681,10 +679,8 @@ class Kirdy:
self._writer.write(bytes(json.dumps(cmd_dict), "UTF-8")) self._writer.write(bytes(json.dumps(cmd_dict), "UTF-8"))
await self._writer.drain() await self._writer.drain()
response = await self._read_response() response = await self._read_response()
try:
if response["msg_type"] == "Acknowledge": if response["msg_type"] == "Acknowledge":
return response return response
except:
retry += 1 retry += 1
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
raise NoAckRecv raise NoAckRecv