我定义了一些时间限制为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
使用以下命令启动我的worker:
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....
有谁知道为什么会这样?
答案 0 :(得分:4)
答案似乎是信号worker_process_init
要求处理程序不会阻塞超过4秒。
http://celery.readthedocs.org/en/latest/userguide/signals.html#worker-process-init
因为我的init函数执行时间较长,所以worker会自动终止。之后它会自然重新启动并再次触发init函数,然后再次终止worker,等等。