Skip to content

Commit

Permalink
network: ensure we pass tasks to asyncio.wait
Browse files Browse the repository at this point in the history
In Python < 3.11, when passing a coroutine to asyncio.wait, it would
automatically be scheduled as a task. This isn't the case anymore with
Python 3.11. Now passing coroutines to asyncio.wait fails with:

 TypeError: Passing coroutines is forbidden, use tasks explicitly.

Let's ensure we schedule the coroutines as tasks before passing them on
to asyncio.wait.

Signed-off-by: Olivier Gayot <[email protected]>
  • Loading branch information
ogayot committed Dec 8, 2023
1 parent 93ab4f9 commit 0b7a4d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion subiquity/server/controllers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ async def wait_for_initial_config(self, context):
with context.child("wait_dhcp"):
try:
await asyncio.wait_for(
asyncio.wait({e.wait() for e in dhcp_events}), 10
asyncio.wait({asyncio.create_task(e.wait()) for e in dhcp_events}),
10,
)
except asyncio.TimeoutError:
pass
Expand Down
4 changes: 3 additions & 1 deletion subiquitycore/controllers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ def error(stage):
return

try:
await asyncio.wait_for(asyncio.wait({e.wait() for e in dhcp_events}), 10)
await asyncio.wait_for(
asyncio.wait({asyncio.create_task(e.wait()) for e in dhcp_events}), 10
)
except asyncio.TimeoutError:
pass

Expand Down

0 comments on commit 0b7a4d1

Please sign in to comment.