推荐学习书目
› 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 · Oct 25, 2016 · 1950 views
    This topic created in 3632 days ago, the information mentioned may be changed or developed.

    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()
    
    Supplement 1  ·  Oct 25, 2016
    用 try 把函数里的代码包起来就好了,不知道为啥不包就不报错。
    R4rvZ6agNVWr56V0
        1
    R4rvZ6agNVWr56V0  
       Oct 26, 2016
    没执行到 add 方法里啊,你 apply_async 调用过后.get() 执行后就知道有报错了啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   964 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:48 · PVG 01:48 · LAX 10:48 · JFK 13:48
    ♥ Do have faith in what you're doing.