python生成器异步使用

import dis,time  # 反汇编
import threading def request():
print('start request')
v = yield
print(v) def target(func):
try:
s = time.time()
print('start target')
c = func()
c.send(None)
time.sleep(7)
c.send(f'done: {time.time()-s}')
except StopIteration:
pass def server(func):
threading.Thread(target=target,args=(func,)).start() server(request)
for i in range(10):
time.sleep(1)
print(i)

运行结果

>>>
start target
start request
0
1
2
3
4
5
done: 7.004955053329468
6
7
8
9
上一篇:IIS部署网站


下一篇:开始VS 2012中LightSwitch系列的第4部分:太多信息了!使用查询来排序和筛选数据