Concurrency - the correct posture for python multi-process + coroutine?
给我你的怀抱
给我你的怀抱 2017-07-05 10:34:33
0
1
999

What is the correct posture of python multi-process coroutine? Is the following code an example of combining multi-process and coroutine?

from multiprocessing import Pool
import gevent
def test1():
    print (12)
    gevent.sleep(1)
    print (34)
def test2():
    print (56)
    gevent.sleep(1)
    print (78)
def coroutine():
    gevent.joinall([
        gevent.spawn(test1),
        gevent.spawn(test2)
    ])
if __name__=="__main__":
    p=Pool()
    for i in range(3):
        p.apply_async(coroutine,args=())
    p.close()
    p.join()
给我你的怀抱
给我你的怀抱

reply all(1)
刘奇

Add a patch and it will be complete.

from gevent import monkey; monkey.patch_all()
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template