【发布时间】:2015-12-18 15:32:43
【问题描述】:
如果单个异步任务超过 Python 中的阈值时间(例如 60 秒),如何在 WINDOWS 中使用多处理终止单个异步任务?
import multiprocessing as mp
def compute(test_num):
return test_num ** 2
def main():
test_num_list = [10, 20, 30, 40, 50, 60, 70, 80]
pool = mp.Pool(processes=3)
results = [pool.apply_async(compute, args=(test_num,)) for test_num in test_num_list]
output = [r.get() for r in results]
print output
【问题讨论】:
-
它显示什么错误?我只是尝试运行它,它对我有用
-
@DorElias 我已经更正了我的问题。请问可以给我答案吗?