我有一个与芹菜和子进程异步执行的耗时的python任务。此芹菜过程也可以使用主管来守护。
Python任务代码:
cmd = 'python' \
+ ' DRScompute.py' \
+ ' --iImage=' + local_filename_image \
+ ' --iData=' + local_filename_annotations \
+ ' --oData=' + output_json_path \
+ ' --oImage=' + output_image_path
print 'Command:', cmd
p = sub.Popen(cmd.split(), stdout=sub.PIPE, stderr=sub.PIPE)
output, errors = p.communicate()
print output
rc = p.wait()
如果我直接从终端运行此python任务(请参见下面的命令),它将完美地执行任务。
芹菜命令:
celery worker -A tasks --loglevel=INFO --concurrency=1 -n worker
但是,如果我使用受监管的(请参见下面的配置)来守护此芹菜进程,它将执行任务,但是会在完成任务之前先运行其余代码。
主管配置:
[program:celery]
command=celery worker -A tasks --loglevel=INFO --concurrency=1 -n worker
directory=/home/admin/creta
user=admin
numprocs=1
stdout_logfile=/home/admin/creta/logs/celery-worker.log
stderr_logfile=/home/admin/creta/logs/celery-worker.log
autostart=true
autorestart=true
startsecs=10
; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600
; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true
; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1000
因此,当我使用主管时,将执行子进程python任务,但在完成耗时的任务之前,它会跳至其余代码。