1
0
Fork 0

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