import threading
import time
gen = None
def longIO():
def run():
print(‘开始耗时操作’)
time.sleep(5)
try:
global gen
gen.send(‘brotech is good’)
except StopIteration as e:
pass
print(‘结束耗时操作’)
threading.Thread(target=run).start()
def reqA():
print(‘开始处理reqA’)
res = yield longIO()
print(‘接收到longIo的响应数据:’, res)
print(‘结束处理reqA’)
def reqB():
print(‘开始处理B’)
print(‘结束处理B’)
def main():
global gen
gen = reqA()
next(gen)
# reqA()
reqB()
if name == ‘main’:
main()