'''
about what
'''
import multiprocessing
import random
import time
def func(arg, name):
print("正在执行{0}...".format(arg))
time.sleep(random.randint(1, 5))
print("进程%d完毕!" % (name))
return random.sample(["fuck", "阿西吧", "雅蠛蝶", "你妹"], 1)
pass
def onFuncReturn(result):
print("得到结果{0}".format(result))
pass
def getPoolResultAsync():
pool = multiprocessing.Pool(3)
reslist = []
for i in range(5):
res = pool.apply_async(func=func, args=("hello", i), callback=onFuncReturn)
print("立刻打印结果:", res)
reslist.append(res)
pool.close()
pool.join()
for res in reslist:
print(res.get())
def getPoolResultSync():
pool = multiprocessing.Pool(3)
reslist = []
for i in range(5):
res = pool.apply(func=func, args=("hello", i))
reslist.append(res)
pool.close()
pool.join()
for res in reslist:
print(res)
if __name__ == "__main__":
getPoolResultAsync()
print("main over")