Python 芹菜:陷入无限重复超时(等待UP消息超时)

Python 芹菜:陷入无限重复超时(等待UP消息超时),python,timeout,celery,Python,Timeout,Celery,我定义了一些时间限制为1200的任务: @celery.task(time_limit=1200) def create_ne_list(text): c = Client() return c.create_ne_list(text) 我还使用worker\u process\u init信号进行初始化,每次新进程启动时: @worker_process_init.connect def init(sender=None, conf=None, **kwargs):

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

@celery.task(time_limit=1200)
def create_ne_list(text):
    c = Client()
    return c.create_ne_list(text)
我还使用
worker\u process\u 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会导致初始化函数被调用三次。现在,我可以发送任务了,它们正在执行中,一切似乎都很顺利

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

[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....
[2014-06-13 09:46:18978:错误/MainProcess]等待来自的UP消息时超时
[2014-06-13 09:46:20000:ERROR/MainProcess]进程“Worker-20381”pid:18953带“信号9(SIGKILL)”退出
//新工人20382开始工作,初始化触发,不久-->
[2014-06-13 09:46:18978:错误/主进程]等待来自的UP消息时超时
[2014-06-13 09:46:20000:ERROR/MainProcess]进程“Worker-20382”pid:18954与“信号9(SIGKILL)”一起退出
//等等。。。。

有人知道为什么会发生这种情况吗?

答案似乎是信号
worker\u process\u init
要求处理程序的阻塞时间不超过4秒


因为我的init函数需要更长的时间来执行,所以worker将自动终止。之后,它会自动重新启动并再次触发init函数,然后导致工作进程再次终止,依此类推。

您可以在第一个任务运行时使用task_prerun信号执行初始化