第十一节 yield实现多任务

import time

def test1():
while True:
print('.....1......')
time.sleep(0.2)
yield


def test2():
while True:
print('......2......')
time.sleep(0.2)
yield


def main():
t1 = test1()
t2 = test2()
while True:
next(t1)
next(t2)

if __name__ == '__main__':
main()
原文地址:https://www.cnblogs.com/kogmaw/p/12575521.html