The StreamWriter.wait_closed() method was introduced in Python 3.7, so
attempting to use it with Python 3.6 raises an exception. This has not
been noticed before because awaiting StreamWriter.wait_closed() is the
last action taken for each TCP connection and unhandled exceptions were
not causing the scripts based on AsyncServer to exit prematurely until
the previous commit.
As per Python documentation [1], awaiting StreamWriter.wait_closed()
after calling StreamWriter.close() is recommended, but not mandatory, so
try to use it if it is available, without taking any fallback action in
case it isn't.
[1] https://docs.python.org/3.13/library/asyncio-stream.html#asyncio.StreamWriter.close
logging.debug("Closing TCP connection from %s", peer)
writer.close()
- await writer.wait_closed()
+ try:
+ # Python >= 3.7
+ await writer.wait_closed()
+ except AttributeError:
+ # Python < 3.7
+ pass
async def _read_tcp_query(
self, reader: asyncio.StreamReader, peer: Peer