您可以看一下pebble库。
from pebble import ProcessPoolfrom concurrent.futures import TimeoutErrordef sometimes_stalling_processing(obs): ... return processed_obswith ProcessPool() as pool: future = pool.map(sometimes_stalling_processing, dataset, timeout=10) iterator = future.result() while True: try: result = next(iterator) except StopIteration: break except TimeoutError as error: print("function took longer than %d seconds" % error.args[1])
文档中的更多示例。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)