在使用 soft_time_limit 的时候遇到了一个问题,debug 信息已经显示类似以下信息:
Soft time limit (180s) exceeded
@celery.task(soft_time_limit=180)
def test_error(para):
do_something...
然后我去查了下 task id,还是处于 starting 状态。 多个任务出现这种情况,有的再过一段时间会变成 SUCCESS,还有的任务就干脆放弃治疗,一直卡在 starting 了。
看了个解决方法,是在调用任务时 catch 错误 SoftTimeLimitExceeded:
from celery.exceptions import SoftTimeLimitExceeded
@app.task
def mytask():
try:
return do_work()
except SoftTimeLimitExceeded:
cleanup_in_a_hurry()
不过我的任务函数 test_error 是在 workflow 里的 chord 调用的,不太好 catch:
chord( ( test_error.s(x) for x in y) , test_result.s() )().get()
我原本还以为 soft_time_limit 算是 time_limit 的不报错版本,会自动 continue 啥的。test_error 这里如果直接使用 time_limit 的话,报错似乎会让 chord 直接失败。
哪位大佬能给个好的解决办法?