美文网首页
python process 进程输出

python process 进程输出

作者: Do_More | 来源:发表于2017-07-15 17:06 被阅读0次
    import multiprocessing as mp
    import threading as td
    
    def job(q):
        res = 0
        for i in range(1000):
            res += i + i ** 2 + i**3
        q.put(res)
    
    if __name__ == '__main__':
        q = mp.Queue()
        p1 = mp.Process(target=job,args=(q,))
        p2 = mp.Process(target=job,args=(q,))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        res1 = q.get()
        res2 = q.get()
        print(res1 + res2)
    
    

    相关文章

      网友评论

          本文标题:python process 进程输出

          本文链接:https://www.haomeiwen.com/subject/afhzhxtx.html