daemonic processes are not allowed to have children


import multiprocessing
import time


def func(msg):
    time.sleep(1)
    print multiprocessing.current_process().name + '-' + msg

    def spider():
        time.sleep(2)
        print multiprocessing.current_process().name + '-' + msg

    try:
        pool1 = multiprocessing.Pool(processes=10)  

        for i in [page for page in range(100)]:
            msg = "word %d" % (i)
            print "msg",msg
            pool1.apply_async(spider, (msg,))
        pool1.close()
        pool1.join()
    except Exception as e :
        print e



if __name__ == "__main__":
    start_time = time.time()

    pool = multiprocessing.Pool(processes=10)  
    results = []
    for i in [page for page in range(10)]:
        msg = "hello %d" % (i)
        results.append(pool.apply_async(func, (msg,)))
    pool.close()
    pool.join()
    print time.time()-start_time
 
子進程不能在通過multiprocessing創建后代進程,否則當父進程退出后,它終結其daemon子進程,那孫子進程就成了孤兒進程了。當嘗試這么做時,會報錯:AssertionError: daemonic processes are not allowed to have children



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM