Python多重处理主要功能即使子进程出错也能等待无限

时间:2018-07-31 07:09:32

标签: python python-2.7 multiprocessing

我使用python(2.7)模块进行多处理,以在我的一个脚本中实现并行处理。

import sys
import multiprocessing

def myfun(file):
  try:
      <my logic>
  except Exception:
    sys.exit(-1)

my_file_list ['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7', 'file8', 'file9', 'file10', 'file11', ]
pool = multiprocessing.Pool(processes=3) 
pool.map(myfun, my_file_list ) 

每当我的函数myfun由于某些文件异常而出错时,我的主函数将陷入无限等待!和我wi ;;必须杀死它。有人可以帮我修复我的代码/逻辑吗?

1 个答案:

答案 0 :(得分:0)

除非您有充分的理由并且知道自己在做什么,否则不要致电const e = [{uniqueId:'',active:'a',qId:10},{uniqueId:'',active:'a',qId:11}] const f = [{uniqueId:50,active:'a',qId:10},{uniqueId:51,active:'a',qId:11},{uniqueId:52,active:'a',qId:13}] const qIds = new Set(e.map(({ qId }) => qId)); console.log(f.filter(({ qId }) => qIds.has(qId)));:管理流程是池的责任。看起来您根本不需要那种try-except逻辑。

相关问题