下面是一些简单的代码:
@shared_task(time_limit=10, soft_time_limit=5)
def check_action():
try:
__import__("time").sleep(100)
except celery.exceptions.SoftTimeLimitExceeded as e:
print("Here", e, type(e))
except BaseException as e:
print("There", e, type(e))
shared_task
具有
time_limit
soft_time_limit
Here
SoftTimeLimitExceeded
异常信息),然后
There
打印时出现一些硬超时异常。
需要软时间限制
celery_1 | [2019-05-31 21:36:36,709: WARNING/MainProcess] There
celery_1 | [2019-05-31 21:36:36,710: WARNING/MainProcess] 10 seconds
celery_1 | [2019-05-31 21:36:36,710: WARNING/MainProcess] <class 'gevent.timeout.Timeout'>
从日志中可以看出,我使用
gevent
升级版1:
问题似乎出在
gevent公司
游泳池(我要搬走吗
--pool=gevent
,一切正常)。
升级版2:
eventlet
游泳池似乎不支持任何超时,即使是硬的。