import time
def work1():
for i in range(5):
print("work1:", i)
yield
time.sleep(0.2)
print("**********")
def work2():
for i in range(5):
print("work2:", i)
yield
time.sleep(0.2)
print("===========")
w1 = work1()
w2 = work2()
while True:
next(w1)
next(w2)
python协程yield方式
最新推荐文章于 2024-06-30 23:16:00 发布