diff options
author | Damien George <damien.p.george@gmail.com> | 2020-03-30 14:58:13 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-02 00:14:18 +1100 |
commit | b389bc0afaaa5a16dc11daaed056d89ea3da3b83 (patch) | |
tree | 832f5198746359a7c009dff8ba34068ecc9c5166 /tests | |
parent | 711dd392d3800f9513c0a534cf8ecd9c3bfd27e0 (diff) | |
download | micropython-b389bc0afaaa5a16dc11daaed056d89ea3da3b83.tar.gz micropython-b389bc0afaaa5a16dc11daaed056d89ea3da3b83.zip |
extmod/uasyncio: Implement Loop.stop() to stop the event loop.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/extmod/uasyncio_loop_stop.py | 45 | ||||
-rw-r--r-- | tests/extmod/uasyncio_loop_stop.py.exp | 7 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/extmod/uasyncio_loop_stop.py b/tests/extmod/uasyncio_loop_stop.py new file mode 100644 index 0000000000..23507f9a7e --- /dev/null +++ b/tests/extmod/uasyncio_loop_stop.py @@ -0,0 +1,45 @@ +# Test Loop.stop() to stop the event loop + +try: + import uasyncio as asyncio +except ImportError: + try: + import asyncio + except ImportError: + print("SKIP") + raise SystemExit + + +async def task(): + print("task") + + +async def main(): + print("start") + + # Stop the loop after next yield + loop.stop() + + # Check that calling stop() again doesn't do/break anything + loop.stop() + + # This await should stop + print("sleep") + await asyncio.sleep(0) + + # Schedule stop, then create a new task, then yield + loop.stop() + asyncio.create_task(task()) + await asyncio.sleep(0) + + # Final stop + print("end") + loop.stop() + + +loop = asyncio.get_event_loop() +loop.create_task(main()) + +for i in range(3): + print("run", i) + loop.run_forever() diff --git a/tests/extmod/uasyncio_loop_stop.py.exp b/tests/extmod/uasyncio_loop_stop.py.exp new file mode 100644 index 0000000000..bada5f0d84 --- /dev/null +++ b/tests/extmod/uasyncio_loop_stop.py.exp @@ -0,0 +1,7 @@ +run 0 +start +sleep +run 1 +run 2 +task +end |