async in multiprocess_pool

from multiprocessing import Pool
import time
import os

def test():
    print('---the process in pool---pid = %d,ppid = %d---'%(os.getpid(),os.getppid()))
    for i in range(3):
        print('---%d -- '%i)
        time.sleep(1)
    return 'haha'

def test2(args):
    print('---callbakc-- func ---pid = %d--',os.getpid())
    print('---callback---args = %s'%args)

pool = Pool(3)
pool.apply_async(func = test,callback = test2)
while True:
    time.sleep(1)
    print('---the main process pid = %d'%os.getpid())

async in multiprocess_pool_第1张图片

你可能感兴趣的:(python)