我使用python(2.7)模块multiprocessing在我的一个脚本中实现并行处理。你知道吗
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由于某些文件异常而出错时,我的主函数就会进入无限等待!我必须杀了它。有人能帮我修改代码/逻辑吗?你知道吗
不要打电话给
sys.exit
,除非你有很好的理由并且知道你在做什么:管理流程是池的责任。看起来除了逻辑你根本不需要尝试。你知道吗相关问题 更多 >
编程相关推荐