Add timeout to connect call

This commit is contained in:
atse 2023-07-31 00:34:09 +08:00 committed by Tse Kwok Yan
parent fc389ab4dd
commit 5651931766
1 changed files with 1 additions and 1 deletions

View File

@ -23,7 +23,7 @@ class Client:
if connected:
return
"""
self._connecting_task = asyncio.create_task(asyncio.open_connection(host, port))
self._connecting_task = asyncio.create_task(asyncio.wait_for(asyncio.open_connection(host, port), timeout))
try:
self._reader, self._writer = await self._connecting_task
except asyncio.CancelledError: