QUERY · ISSUE
extmod/uasyncio: gather gets stuck if you pass an empty list in v1.19
bugextmod
Hello, folks
This is pretty straightforward in v1.17 and v1.18 passing an empty list to gather will return (or yield) whereas in v1.19 it gets stuck for ever. Not sure if this is a new intended behavior (which is not in the docs?). I'm assuming this is a bug as there is nothing in the release notes.
Cheers,
CANDIDATE · ISSUE
extmod/uasyncio gather return_exceptions=True does not return exceptions
extmod
This script works as expected under CPython but not under MicroPython:
try:
import uasyncio as asyncio
except ImportError:
import asyncio
async def barking(n):
print('Start barking')
for _ in range(6):
await asyncio.sleep(1)
print('Done barking.')
return 2 * n
async def foo(n):
print('Start timeout coro foo()')
while True:
await asyncio.sleep(1)
n += 1
return n
async def bar(n):
print('Start cancellable bar()')
while True:
await asyncio.sleep(1)
n += 1
return n
async def do_cancel(task):
await asyncio.sleep(5)
print('About to cancel bar')
task.cancel()
async def main():
tasks = [asyncio.create_task(bar(70))]
tasks.append(barking(21))
tasks.append(asyncio.wait_for(foo(10), 7))
asyncio.create_task(do_cancel(tasks[0]))
res = None
try:
res = await asyncio.gather(*tasks, return_exceptions=True)
except asyncio.TimeoutError:
print('Timeout')
except asyncio.CancelledError:
print('Cancelled')
print('Result: ', res)
asyncio.run(main())
Under CPython:
Start cancellable bar()
Start barking
Start timeout coro foo()
About to cancel bar
Done barking.
Result: [CancelledError(), 42, TimeoutError()]
MicroPython:
Start cancellable bar()
Start barking
Start timeout coro foo()
About to cancel bar
Cancelled
Result: None
The cancelled exception has propagated to the caller and the timeout exception has apparently vanished.