diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-06-08 16:01:38 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-06-19 17:33:03 +1000 |
commit | 6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54 (patch) | |
tree | 08f41a4d0cd48fa5c0bc49519832ac2faba6923a /tests/extmod/asyncio_cancel_fair2.py | |
parent | 2fbc08c462e247e7f78460783c9a07c76c5b762e (diff) | |
download | micropython-6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54.tar.gz micropython-6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54.zip |
tests: Rename uasyncio to asyncio.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/extmod/asyncio_cancel_fair2.py')
-rw-r--r-- | tests/extmod/asyncio_cancel_fair2.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/extmod/asyncio_cancel_fair2.py b/tests/extmod/asyncio_cancel_fair2.py new file mode 100644 index 0000000000..577823204f --- /dev/null +++ b/tests/extmod/asyncio_cancel_fair2.py @@ -0,0 +1,34 @@ +# Test fairness of cancelling a task +# That tasks which keeps being cancelled by multiple other tasks gets a chance to run + +try: + import asyncio +except ImportError: + print("SKIP") + raise SystemExit + + +async def task_a(): + try: + while True: + print("sleep a") + await asyncio.sleep(0) + except asyncio.CancelledError: + print("cancelled a") + + +async def task_b(id, other): + while other.cancel(): + print("sleep b", id) + await asyncio.sleep(0) + print("done b", id) + + +async def main(): + t = asyncio.create_task(task_a()) + for i in range(3): + asyncio.create_task(task_b(i, t)) + await t + + +asyncio.run(main()) |