解決單線程下的io,最大化提高效率異步
import geventfrom gevent import monkeymonkey.patch_all()import timedef eat(name): print('%s eat 1' %name) # gevent.sleep(2) time.sleep(2) print('%s eat 2' %name)def play(name): print('%s play 1' %name) # gevent.sleep(2) time.sleep(2) print('%s play 2' %name)g1=gevent.spawn(eat,'egon') #異步執行這個eat任務,後面egon就是給他傳的參數g2=gevent.spawn(play,name='egon')# g1.join()# g2.join()gevent.joinall([g1,g2])print('主')