Skip to content

Commit cc0e4a2

Browse files
maxileithpostlund
authored andcommitted
Wrap coroutines passed to asyncio.wait with create_tasks asyncio.wait does not support passing coroutines since python 3.11
1 parent d8c6b4d commit cc0e4a2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pyatv/scripts/atvscript.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ async def wait_for_input(loop, abort_sem):
164164
reader = asyncio.StreamReader(loop=loop)
165165
reader_protocol = asyncio.StreamReaderProtocol(reader)
166166
await loop.connect_read_pipe(lambda: reader_protocol, sys.stdin)
167+
reader_readline = asyncio.create_task(reader.readline())
168+
abort_sem_acquire = asyncio.create_task(abort_sem.acquire())
167169
await asyncio.wait(
168-
[reader.readline(), abort_sem.acquire()], return_when=asyncio.FIRST_COMPLETED
170+
[reader_readline, abort_sem_acquire], return_when=asyncio.FIRST_COMPLETED
169171
)
170172

171173

pyatv/support/knock.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ async def knock(address: IPv4Address, ports: List[int], timeout: float) -> None:
5151
# yield to the event loop to ensure we do not block
5252
await asyncio.sleep(0)
5353
_LOGGER.debug("Knocking at port %s on %s", port, address)
54-
tasks.append(asyncio.ensure_future(_async_knock(address, port, knock_runtime)))
54+
tasks.append(
55+
asyncio.ensure_future(
56+
asyncio.create_task(_async_knock(address, port, knock_runtime))
57+
)
58+
)
5559
_, pending = await asyncio.wait(tasks, return_when=FIRST_EXCEPTION)
5660
if pending:
5761
for task in pending:

0 commit comments

Comments
 (0)