search

Home  >  Q&A  >  body text

Concurrency - the correct posture for python multi-process + coroutine?

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()
给我你的怀抱给我你的怀抱2732 days ago1064

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-07-05 10:36:33

    Add a patch and it will be complete.

    from gevent import monkey; monkey.patch_all()

    reply
    0
  • Cancelreply