Skip to content

サンプル Asyncio

TakeoTakahashi2020 edited this page Sep 23, 2021 · 2 revisions

image

  • EK-RA6M2ボードでは、CPython 3.8 Asyncioサブセット機能が使用できます。
  • 3つのインスタンスでそれぞれカウントした値を表示します。
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