我试图使用此命令优雅地关闭芹菜工人。
ps aux | grep celery worker | awk '{print $2}' | xargs kill -SIGINT
但是,某些工作进程仍在抛出 WorkerLostError。这是芹菜工人日志的一部分,其中一名工人在完成任务之前被杀死
[2016-01-18 09:10:56,667: INFO/MainProcess] Received task: task[b83163b4-9fd6-4c06-88bb-8cf8fc98bb23]
[2016-01-18 09:10:58,390: INFO/MainProcess] Received task: task[d5239190-2cea-4ee1-bac6-7600a9f05839]
[2016-01-18 09:11:00,621: INFO/MainProcess] Received task: task[1139f6f8-31b5-449b-9425-0cf6943496d4]
[2016-01-18 09:11:01,543: INFO/MainProcess] Received task: task[0547455c-83e4-4a9e-a0a5-e872afdbbc62]
[2016-01-18 09:11:01,695: INFO/MainProcess] Received task: task[520b41da-7e3a-4c9d-a807-8e11aebd4bcd]
[2016-01-18 09:11:02,286: INFO/MainProcess] Task task[d5239190-2cea-4ee1-bac6-7600a9f05839] succeeded in 3.8944714s: []
worker: Hitting Ctrl+C again will terminate all running tasks!
worker: Warm shutdown (MainProcess)
[2016-01-18 09:11:04,451: INFO/MainProcess] Task task[520b41da-7e3a-4c9d-a807-8e11aebd4bcd] succeeded in 2.754699837s: []
[2016-01-18 09:11:04,497: ERROR/MainProcess] Task task[b83163b4-9fd6-4c06-88bb-8cf8fc98bb23] raised unexpected: WorkerLostError('Worker exited prematurely: exitcode 0.',)
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/billiard-3.3.0.22-py2.6.egg/billiard/pool.py", line 1175, in mark_as_worker_lost
human_status(exitcode)),
WorkerLostError: Worker exited prematurely: exitcode 0.
[2016-01-18 09:11:05,500: INFO/MainProcess] Task task[1139f6f8-31b5-449b-9425-0cf6943496d4] succeeded in 4.877286218s: []
[2016-01-18 09:11:06,002: INFO/MainProcess] Task task[0547455c-83e4-4a9e-a0a5-e872afdbbc62] succeeded in 4.457699244s: []
-------------- celery@ip-10-0-1-78 v3.1.19 (Cipater)
---- **** -----
--- * *** * -- Linux-3.14.26-24.46.amzn1.x86_64-x86_64-with-glibc2.2.5
下面的代码片段将优雅地关闭工作线程。 即,一旦正在执行的作业完成,工作线程将被关闭。
from celery import Celery
celery = Celery('vwadaptor', broker='redis://workerdb:6379/0',backend='redis://workerdb:6379/0')
celery.control.broadcast('shutdown', destination=[<celery_worker_name>])
这不是关闭工人的非常优雅的方式。
我建议使用 supervisord 来管理您的工作人员 - 芹菜源中有一个示例配置文件,您可以将其用作起点。