2017-08-17 57 views
1

在dask.distributed上使用期货时,有没有办法区分目前正在评估的期货pending和仍然在队列中?如何区分排队和正在运行的期货(并杀死运行时间过长的期货)

原因是我将大量任务(〜8000)提交给较小的工作人员(100),因此不是所有任务都可以立即处理。这些任务涉及调用第三方可执行文件(,通过subprocess.check_output),在一些极少数情况下会进入无限循环。

因此,我想取消期货运行时间太长(使用任意超时)。然而,似乎没有办法确定未来是否长期处于pending状态,因为计算时间比平时长,或者仅仅因为必须等待工作人员可用。

我的设置涉及一个分别运行dask-schedulerdask-worker作业/作业数组的SGE群集。 我试图在提交Python函数直接设置超时,使用@timeout_decorator.timeout(60, use_signals=False)timeout_decorator package,但得到了以下错误:

"daemonic processes are not allowed to have children" 

任何帮助将非常感激。

回答

0

不,您无法确定任务是否已开始执行。通常我们建议将这个逻辑放在任务本身中,正如你试图用你的超时修饰器一样。

我推荐使用timeout=关键字本身。我怀疑这会更简单,并有更高的工作顺利。

+0

感谢您的快速答复。我正在运行Python 2,其中'subprocess'缺少'timeout ='关键字,但我可以在下面的答案中获得与代码相同的效果。尽管这是一个特定于实现的细节,所以我将这个答案标记为正确的答案。 – user3098840

0

对于运行Python 2的用户,timeout=关键字在subprocess.check_output中不可用。

我能够通过使用subprocess.Popen代替,以获得预期的效果,这立即返回:

import subprocess 
import shlex # useful to split up arguments for subprocess 
import time 

p = subprocess.Popen(shlex.split('/path/to/binary arg1 arg2'), 
        stderr=subprocess.STDOUT) 
for _ in range(60): # wait for up to 60 seconds 
    if p.poll() is not None: 
     break # process completed 
    else: 
     time.sleep(1.0) # give it more time 
if p.poll() is None: # time is up, are we done? 
    try: 
     p.kill() 
    except: 
     raise 
    raise RuntimeError('Binary failed to complete in time.') 
相关问题