1

在 dask.distributed 上使用期货时,有没有办法区分pending当前正在评估的期货和仍在队列中的期货?

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

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

我的设置涉及一个 SGE 集群,分别运行 adask-schedulerdask-workerjob/job-array。@timeout_decorator.timeout(60, use_signals=False)我尝试使用timeout_decorator 包直接在提交的 Python 函数中设置超时,但出现以下错误:

"daemonic processes are not allowed to have children"

任何帮助将非常感激。

4

2 回答 2

0

不,您无法确定任务是否已开始执行。通常,我们建议将此逻辑放在任务本身中,就像您尝试使用超时装饰器一样。

我建议改为尝试timeout=关键字subprocess.check_outputs本身。我怀疑这会更简单,并且更有可能顺利工作。

于 2017-08-17T20:34:06.400 回答
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.')
于 2017-08-18T00:59:50.440 回答