import time
# yield配合next使用
def work1():
while True:
print("----work1---")
yield
time.sleep(0.3)
def work2():
while True:
print("----work2---")
yield
time.sleep(0.3)
def main():
w1 = work1()
w2 = work2()
while True:
next(w1)
next(w2)
if __name__ == "__main__":
main( )
2020-05-08