线程_multiprocessing异步

from multiprocessing import Pool
import time
import os

def test():
    print("---进程池中的进程---pid=%d,ppid=%d--"%(os.getpid(),os.getppid()))
    for i in range(3):
        print("----%d---"%i)
        time.sleep(1)
    return "hahah"

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

if __name__ == '__main__':
    pool = Pool(3)
    pool.apply_async(func=test,callback=test2)
    # 异步执行
    time.sleep(5)

    print("----主进程-pid=%d----"%os.getpid())

2020-05-07

posted @ 2020-05-07 20:52  CodeYaSuo  阅读(249)  评论(0编辑  收藏  举报