gevent. Python

import gevent.monkey
gevent.monkey.patch_all()




def write_to_file(file_name, text):
    text = str(text)
    a = open(file_name, 'a')
    a.write(text + "\n")
    a.close()


def foo(i,a,b,c):
    print i,a,b,c
    # gevent.sleep(0)
    write_to_file("a",i)
    print "Done"


task = [gevent.spawn(foo,i,1,2,3) for i in range(1000000)]
gevent.joinall(task)




坑点
https://www.jianshu.com/p/861f29ac68e8

 

上一篇:使用gevent在应用程序上下文之外工作的烧瓶蓝图


下一篇:python 协程