【问题标题】:Celery: stuck in infinitly repeating timeouts (Timed out waiting for UP message)芹菜:坚持无限重复超时(等待UP消息超时)
【发布时间】:2014-06-13 08:38:34
【问题描述】:

我定义了一些时间限制为 1200 的任务:

@celery.task(time_limit=1200)
def create_ne_list(text):
    c = Client()
    return c.create_ne_list(text)

我也在使用worker_process_init 信号进行一些初始化,每次新进程启动时:

@worker_process_init.connect
def init(sender=None, conf=None, **kwargs):
    init_system(celery.conf)
    init_pdf(celery.conf)

这个初始化函数需要几秒钟来执行。

除此之外,我正在使用以下配置:

CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
BROKER_URL = 'amqp://'
CELERY_RESULT_BACKEND = 'amqp://'
CELERY_TIMEZONE = 'Europe/Berlin'
CELERY_ENABLE_UTC = True

并使用以下命令启动我的工作人员:

celery -A isc worker -l info --concurrency=3

正如预期的那样,启动 worker 会导致初始化函数被调用 3 次。现在,我可以发送任务并且它们正在执行并且一切似乎都运行顺利。

但是:一旦一个任务超过了它的时间限制,worker就会陷入一个无限循环的产生并因为超过时间限制而再次被杀死。

[2014-06-13 09:46:18,978: ERROR/MainProcess] Timed out waiting for UP message from <Worker(Worker-20381, started daemon)>
[2014-06-13 09:46:20,000: ERROR/MainProcess] Process 'Worker-20381' pid:18953 exited with 'signal 9 (SIGKILL)'
// new worker 20382 getting started, initialization getting triggerd and soon after that -->
[2014-06-13 09:46:18,978: ERROR/MainProcess] Timed out waiting for UP message from <Worker(Worker-20382, started daemon)>
[2014-06-13 09:46:20,000: ERROR/MainProcess] Process 'Worker-20382' pid:18954 exited with 'signal 9 (SIGKILL)'
// and so on....

有人知道为什么会这样吗?

【问题讨论】:

    标签: python timeout celery


    【解决方案1】:

    答案似乎是信号worker_process_init 要求处理程序的阻塞时间不超过4 秒。

    http://celery.readthedocs.org/en/latest/userguide/signals.html#worker-process-init

    由于我的init函数执行时间较长,worker会自动终止。之后它自然会重新启动并再次触发 init 函数,然后导致 worker 再次被终止,依此类推。

    【讨论】:

    • 第一个任务运行时可以使用task_prerun信号进行初始化
    猜你喜欢
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 2022-12-15
    • 1970-01-01
    相关资源
    最近更新 更多