Python multiprocessing Process crashes silently

后端 未结 3 1121
北荒
北荒 2021-02-14 02:08

I\'m using Python 2.7.3. I have parallelised some code using subclassed multiprocessing.Process objects. If there are no errors in the code in my subclassed Process

3条回答
  •  佛祖请我去吃肉
    2021-02-14 02:40

    I suggest such workaround for showing process's exceptions

    from multiprocessing import Process
    import traceback
    
    
    run_old = Process.run
    
    def run_new(*args, **kwargs):
        try:
            run_old(*args, **kwargs)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            traceback.print_exc(file=sys.stdout)
    
    Process.run = run_new
    

提交回复
热议问题