From b22abcdbbedb0f7583b19031fd65e19b3883671d Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 21 Jul 2022 09:54:02 +1000 Subject: [PATCH] extmod/uasyncio: Handle gather with no awaitables. This previously resulted in gather() yielding but with no way to be resumed. Signed-off-by: Jim Mussared --- extmod/uasyncio/funcs.py | 3 +++ tests/extmod/uasyncio_gather.py | 5 +++++ tests/extmod/uasyncio_gather.py.exp | 2 ++ 3 files changed, 10 insertions(+) diff --git a/extmod/uasyncio/funcs.py b/extmod/uasyncio/funcs.py index a1d38fbcbf..96883e4fe1 100644 --- a/extmod/uasyncio/funcs.py +++ b/extmod/uasyncio/funcs.py @@ -62,6 +62,9 @@ class _Remove: async def gather(*aws, return_exceptions=False): + if not aws: + return [] + def done(t, er): # Sub-task "t" has finished, with exception "er". nonlocal state diff --git a/tests/extmod/uasyncio_gather.py b/tests/extmod/uasyncio_gather.py index c081221c9f..af6ea555ab 100644 --- a/tests/extmod/uasyncio_gather.py +++ b/tests/extmod/uasyncio_gather.py @@ -53,6 +53,11 @@ async def main(): print("====") + # Gather with no awaitables + print(await asyncio.gather()) + + print("====") + # Test return_exceptions, where one task is cancelled and the other finishes normally tasks = [asyncio.create_task(task(1)), asyncio.create_task(task(2))] tasks[0].cancel() diff --git a/tests/extmod/uasyncio_gather.py.exp b/tests/extmod/uasyncio_gather.py.exp index a5ea47ab50..371d1ae60d 100644 --- a/tests/extmod/uasyncio_gather.py.exp +++ b/tests/extmod/uasyncio_gather.py.exp @@ -9,6 +9,8 @@ Task C: Compute factorial(4)... Task C: factorial(4) = 24 [2, 6, 24] ==== +[] +==== start 2 end 2 [CancelledError(), 2]