mirror of
https://github.com/W3SLAV/micropython.git
synced 2025-06-19 20:15:33 -04:00

And use `asyncio.new_event_loop()` where possible. This change is needed because CPython 3.12 deprecated the `get_event_loop()` function. Signed-off-by: Damien George <damien@micropython.org>
35 lines
697 B
Python
35 lines
697 B
Python
# Test Loop.new_event_loop()
|
|
# Note: CPython deprecated get_event_loop() so this test needs a .exp
|
|
|
|
try:
|
|
import asyncio
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
|
|
async def task():
|
|
for i in range(4):
|
|
print("task", i)
|
|
await asyncio.sleep(0)
|
|
await asyncio.sleep(0)
|
|
|
|
|
|
async def main():
|
|
print("start")
|
|
loop.create_task(task())
|
|
await asyncio.sleep(0)
|
|
print("stop")
|
|
loop.stop()
|
|
|
|
|
|
# Use default event loop to run some tasks
|
|
loop = asyncio.get_event_loop()
|
|
loop.create_task(main())
|
|
loop.run_forever()
|
|
|
|
# Create new event loop, old one should not keep running
|
|
loop = asyncio.new_event_loop()
|
|
loop.create_task(main())
|
|
loop.run_forever()
|