Micropython 简单的队列任务异步任务框架 micropython-aioschedule

https://github.com/ThinkTransit/micropython-aioschedule

micropython-aioschedule 储备知识

及其简单调用

import schedule

async def job():
    print("I'm working...")
schedule.every(1).minutes.do(job)

async def job_with_argument(name):
    print(f"I am {name}")
schedule.every(10).seconds.do(job_with_argument, name="MicroPython")

标准调用

import uasyncio as asyncio


async def job():
    print("I'm working...")
schedule.every(1).minutes.do(job)


async def job_with_argument(name):
    print(f"I am {name}")
schedule.every(10).seconds.do(job_with_argument, name="MicroPython")


async def main_loop():
    # Create the scheduling task
    t = asyncio.create_task(schedule.run_forever())
    await t

try:
    asyncio.run(main_loop())
except KeyboardInterrupt:
    print('Interrupted')
except Exception as e:
    print("caught")
    print(e)
finally:
    asyncio.new_event_loop()

发表回复