Skip to content

Sample Asyncio

TakeoTakahashi2020 edited this page Sep 23, 2021 · 2 revisions

image

  • For the EK-RA6M2 board, CPython 3.8 Asyncio subset feature can be used.
  • Three instances are independently created, count every 1s.
import uasyncio as asyncio
async def bar(x):
  count = 0
  while True:
    count += 1
    print('Instance: {} count: {}'.format(x, count))
    await asyncio.sleep(1)   # Pause 1s

async def main():
  for x in range(3):
    asyncio.create_task(bar(x))
  await asyncio.sleep(10)

asyncio.run(main())

image

Home

ホーム

Clone this wiki locally