zoukankan      html  css  js  c++  java
  • 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


    如果觉得对您有帮助,麻烦您点一下推荐,谢谢!



    好记忆不如烂笔头
  • 相关阅读:
    主键、外键和索引的区别
    设置session超时的三种方式
    redis常用操作
    timestamp 转 date 处理后再转timestamp
    fragment在水平/垂直时的应用
    Activity堆栈管理
    ORMLite的使用
    onItemLongClick事件的监听
    Bundle的使用
    有关implicit Intent的使用
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/14525997.html
Copyright © 2011-2022 走看看