I would like to wait only 5 seconds for a response; if it does not arrive, just move forward.
async def Test(self, _connection):
_connection.write('heartbeatn'.encode('utf-8'))
try:
length = await asyncio.wait_for(_connection.read_bytes(4), timeout=5)
return length
except asyncio.TimeoutError:
print("The read operation timed out.")
except Exception:
pass
This code works but in case I try to read data again, the following message is printed:
Already reading
I took a look into tornado code and it looks like they do not handle properly the asyncio.CancelledError
fot this case (not sure if this is possible).