multiprocessing 的 debug 问题 ?

2016-10-25 04:05:10 +08:00
 fengxiang

multiprocessing 的子进程错误完全没有错误提示,要怎样才能 debug 呢 ?

环境是 windows python 2.7

例如下面这段带码

#-*-coding:utf-8-*-
import multiprocessing
from multiprocessing import Pool,Process,Queue
import time
import pdb

def add(i,item,queue):
    item["i"] = i
    queue.put(item)

def store(queue):
    time.sleep(1)
    while True:
        print queue.get()

if __name__ == "__main__":
    item = {}
    manager = multiprocessing.Manager()
    queue = manager.Queue()
    pool = Pool()
    pool.apply_async(store,args = (queue,))
    try:
        for i in range(10):
            pool.apply_async( add, args = (i,item,queue,"这里多了个参数但没任何错误提示"))
            #pool.apply_async( add, args = (i,item,queue)) #这样可以正常运行
    except Exception,e:
        print Exception,":",e
    time.sleep(2)
    pool.terminate()
    pool.join()
1388 次点击
所在节点    Python
1 条回复
GeekGao
2016-10-26 14:54:32 +08:00
没执行到 add 方法里啊,你 apply_async 调用过后.get() 执行后就知道有报错了啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/315186

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX