目前尚不清楚如何正确超时joblib的工作人员
Parallel
在python中。其他人也有类似的问题
here
,
here
,
here
和
here
.
在我的示例中,我使用了一个50人的池
joblib
具有
threading
后端。
并行调用(线程):
output = Parallel(n_jobs=50, backend = 'threading')
(delayed(get_output)(INPUT)
for INPUT in list)
在这里
平行的
挂起时无错误
len(list) <= n_jobs
但只有当
n_jobs => -1
.
为了避免这个问题,人们
instructions
关于如何为
平行的
功能(
get_output(INPUT)
)在上述示例中)使用
multiprocessing
:
主要功能(装饰):
@with_timeout(10) # multiprocessing
def get_output(INPUT): # threading
output = do_stuff(INPUT)
return output
多处理装饰器:
def with_timeout(timeout):
def decorator(decorated):
@functools.wraps(decorated)
def inner(*args, **kwargs):
pool = multiprocessing.pool.ThreadPool(1)
async_result = pool.apply_async(decorated, args, kwargs)
try:
return async_result.get(timeout)
except multiprocessing.TimeoutError:
return
return inner
return decorator
将decorator添加到其他工作代码中会导致内存泄漏,超过超时时间的2倍,再加上eclipse崩溃。
装修工的漏洞在哪里?
如何在python中的多处理过程中超时线程?