异步
同步调用就是你喊你朋友吃饭,你朋友在忙,你就一直在那等,等你朋友忙完了,你们一起去
异步调用就是你喊你朋友吃饭,你朋友说知道了,待会忙完去找你,你就去做别的了。
frommultiprocessingimportPool
importtime
importos
deftest()
/p>
print(---进程池中的进程---pid=%d,ppid=%d--%(os.getpid(),os.getppid()))
foriinrange(3)
/p>
print(----%d---%i)
time.sleep(1)
returnhahah
deftest2(args)
/p>
print(---callbackfunc--pid=%d%os.getpid())
print(---callbackfunc--args=%s%args)
pool=Pool(3)
pool.apply_async(func=test,callback=test2)
time.sleep(5)
print(----主进程-pid=%d----%os.getpid())
运行结果:
---进程池中的进程---pid=,ppid=--
----0---
----1---
----2---
---callbackfunc--pid=
---callbackfunc--args=hahah
----主进程-pid=----