生成器实现多任务
from queue import Queue
q = Queue()
def func1():
while not q.empty():
i = q.get()
print(f'------func1------{i}')
yield i
def func2():
while not q.empty():
i = q.get()
print(f'------func2------{i}')
yield i
for i in range(10):
q.put(i)
f1 = func1()
f2 = func2()
while True:
try:
print(next(f1))
print(next(f2))
except StopIteration:
break