进程池:僵尸进程和主进程挂起

2024-05-18 11:06:17 发布

您现在位置:Python中文网/ 问答频道 /正文

使用多处理python模块,我得到了大量的僵尸进程,我的主应用程序永远不会结束。你知道吗

代码非常简单 从多处理导入池

  def __name__ == '__main__':
     thread_pool = Pool(5)
     full_path = ['c:/abc/abc.json', 'c:/abc/abc1.json'] # This goes on for 30 files
     final_output = thread_pool.map(do_work, full_path)
     thread_pool.close()
     thread_pool.join()

def do_work(full_path):
  i = 0
  huge_data = json.loads(full_path)
  for element in huge_data:
     if(element['flag'] == '1'):
         i = i +1
  return ({"Total": i})

Tags: 模块pathjsonfordatadefelementdo