From 0b7a4d16af7fee38b45127dea5965ffe878513a1 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 8 Dec 2023 14:21:54 +0100 Subject: [PATCH] network: ensure we pass tasks to asyncio.wait 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 --- subiquity/server/controllers/network.py | 3 ++- subiquitycore/controllers/network.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/subiquity/server/controllers/network.py b/subiquity/server/controllers/network.py index 00f90094b..869036d72 100644 --- a/subiquity/server/controllers/network.py +++ b/subiquity/server/controllers/network.py @@ -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 diff --git a/subiquitycore/controllers/network.py b/subiquitycore/controllers/network.py index 983606a51..b2cdbe71b 100644 --- a/subiquitycore/controllers/network.py +++ b/subiquitycore/controllers/network.py @@ -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