Cron vs APscheduler vs something,间隔2秒
我需要使用一段python代码,以2秒的固定间隔从串行连接中提取数据。该软件在Raspberry Pi 24/7上运行 在我看来,我有三个选择:Cron vs APscheduler vs something,间隔2秒,cron,apscheduler,Cron,Apscheduler,我需要使用一段python代码,以2秒的固定间隔从串行连接中提取数据。该软件在Raspberry Pi 24/7上运行 在我看来,我有三个选择: 将python脚本作为服务启动(使用systemd)并使用APscheduler 使用cron作业(可能吗?) 使用另一种解决方案 推荐的方法是什么?以下是您如何在 apscheduler还支持异步代码 from apscheduler.schedulers.asyncio import AsyncIOScheduler async def pul
apscheduler
还支持异步代码
from apscheduler.schedulers.asyncio import AsyncIOScheduler
async def pull_data():
await print("code comes here")
scheduler = AsyncIOScheduler()
scheduler.add_job(pull_data, "interval", seconds=2)
scheduler.start()
您还可以使用轻量级python库完成这项工作。
from apscheduler.schedulers.asyncio import AsyncIOScheduler
async def pull_data():
await print("code comes here")
scheduler = AsyncIOScheduler()
scheduler.add_job(pull_data, "interval", seconds=2)
scheduler.start()
import time
import schedule
def pull_data():
print("code comes here")
schedule.every(2).seconds.do(pull_data)
while True:
schedule.run_pending()
time.sleep(1)