gpt4 book ai didi

python - celery 任务中的软超时和超时不起作用

转载 作者:太空狗 更新时间:2023-10-30 01:22:10 27 4
gpt4 key购买 nike

我有一个平均需要 20 秒的任务。我想为这个任务设置软超时和硬超时。我这样定义它:

@app.task(ignore_result=True, timeout=100, soft_timeout=50)
def MYTASK(SOMEPARAMS):
# MYTASK

但实际上并没有用。我用这个参数测试它:

@app.task(ignore_result=True, timeout=1, soft_timeout=1)
def MYTASK(SOMEPARAMS):
# MYTASK

但我的任务工作正常,它们需要超过 1 秒的时间,而这是永远不应该完成的。

为什么超时不起作用?

编辑:当我在我的日志中使用 1 秒超时时,我看到这样的打印:

[2014-08-22 12:51:00,003: INFO/MainProcess] Task MYTASK[56002e72-a093-46c6-86cd-4c7b7e6ea7c3] succeeded in 15.549023876s: None

最佳答案

使用time_limitsoft_time_limit 参数:

@task(time_limit=2, soft_time_limit=1)
def mytask():
pass

另请注意:

Time limits do not currently work on Windows and other platforms that do not support the SIGUSR1 signal.

关于python - celery 任务中的软超时和超时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25442482/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com