gevent的同步与异步
from gevent import spawn,joinall,monkey;monkey.patch_all() import time def task(pid): time.sleep(0.5) print('Task %s done' % pid) def synchronous(): #普通 for i in range(10): task(i) def asynchronous(): g_l=[spawn(task,i) for i in range(10)] #协程 joinall(g_l) if __name__ == '__main__': start = time.time() print('Synchronous:') synchronous() print('普通',time.time() - start) start_vip = time.time() print('Asynchronous:') asynchronous() print('vip:::',time.time() - start_vip) #速度可以快十倍
异步执行比同步执行根据任务量可以快数倍乃至n倍
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/7459148.html