V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fengxiang
V2EX  ›  Python

multiprocessing 的 debug 问题 ?

  •  
  •   fengxiang · 2016-10-25 04:05:10 +08:00 · 1385 次点击
    这是一个创建于 2742 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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()
    
    第 1 条附言  ·  2016-10-25 15:44:21 +08:00
    用 try 把函数里的代码包起来就好了,不知道为啥不包就不报错。
    GeekGao
        1
    GeekGao  
       2016-10-26 14:54:32 +08:00
    没执行到 add 方法里啊,你 apply_async 调用过后.get() 执行后就知道有报错了啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2003 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 00:02 · PVG 08:02 · LAX 17:02 · JFK 20:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.