我定义了一些时间为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
不出所料,启动工作程序会导致初始化函数被调用3次.现在,我可以发送任务,并且它们正在执行,一切似乎都运行顺利.
但是:一旦任务超过其时间限制,工作人员将陷入无限的产卵循环中,并由于超过时间限制而再次被杀死.
[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....
有谁知道为什么会这样?
解决方法:
答案似乎是信号worker_process_init要求处理程序不阻塞超过4秒.
http://celery.readthedocs.org/en/latest/userguide/signals.html#worker-process-init
由于我的init函数执行时间较长,因此该工作程序将自动终止.之后,它自然地重新启动并再次触发init函数,然后导致工作器再次终止,依此类推.