本站改版新增arduino频道
协程demo
#python 协程demo import time taskcount=3 def task1(): while True: print("-----i am task1-----") yield(100) def task2(): while True: print("-----i am task2-----") yield(200) def task3(): while True: print("-----i am task3-----") yield(300) timerlist=[0,0,0] #任务时间队列 tasklist=[task1(),task2(),task3()] def updatetimers(): for i in range(0,taskcount): if timerlist[i]>0: timerlist[i]=timerlist[i]-1 def runtasks(): for i in range(0,taskcount): if timerlist[i]==0: timerlist[i]=next(tasklist[i]) while True: time.sleep(0.001) updatetimers() runtasks()
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0091450214385986 seconds