mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-27 12:55:32 +01:00
Fix process_task not ending correctly (#271)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
4363960be3
commit
712f23d2b2
@ -107,6 +107,8 @@ class APIConnection:
|
||||
|
||||
self._to_process: asyncio.Queue[message.Message] = asyncio.Queue()
|
||||
|
||||
self._process_task: Optional[asyncio.Task[None]] = None
|
||||
|
||||
async def _cleanup(self) -> None:
|
||||
"""Clean up all resources that have been allocated.
|
||||
|
||||
@ -116,6 +118,12 @@ class APIConnection:
|
||||
await self._frame_helper.close()
|
||||
self._frame_helper = None
|
||||
|
||||
if self._process_task is not None:
|
||||
self._process_task.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
await self._process_task
|
||||
self._process_task = None
|
||||
|
||||
if self._socket is not None:
|
||||
self._socket.close()
|
||||
self._socket = None
|
||||
@ -202,7 +210,7 @@ class APIConnection:
|
||||
# Create read loop
|
||||
asyncio.create_task(self._read_loop())
|
||||
# Create process loop
|
||||
asyncio.create_task(self._process_loop())
|
||||
self._process_task = asyncio.create_task(self._process_loop())
|
||||
|
||||
async def _connect_hello(self) -> None:
|
||||
"""Step 4 in connect process: send hello and get api version."""
|
||||
|
Loading…
Reference in New Issue
Block a user