我有以下代码,我在芹菜任务中使用子进程运行shell脚本。它没有工作,因为我没有收到错误或任何前进的进展,或芹菜任务的任何输出:
以下是执行任务的代码:
def run_shell_command(command_line):
command_line_args = shlex.split(command_line)
logging.info('Subprocess: "' + command_line + '"')
try:
command_line_process = subprocess.Popen(
command_line_args,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
for l in iter(command_line_process.stdout.readline,b''):
print l.strip()
command_line_process.communicate()
command_line_process.wait()
except (OSError, subprocess.CalledProcessError) as exception:
logging.info('Exception occured: ' + str(exception))
logging.info('Subprocess failed')
return False
else:
# no exception was raised
logging.info('Subprocess finished')
return True
从任务中调用它:
@app.task
def execute(jsonConfig, projectName, tagName, stage, description):
command = 'python ' + runScript + ' -c ' + fileName
run_shell_command(command)
这里是python" runScript"本身就是调用子进程,并执行一个长时间运行的任务。可能是什么问题
日志记录级别已设置为INFO:
logging.basicConfig(filename='celery-execution.log',level=logging.INFO)
芹菜工人如下:
celery -A celery_worker worker --loglevel=info
我可以看到子进程正在启动:
[2016-05-03 01:08:55,126: INFO/Worker-2] Subprocess: "python runScript.py -c data/confs/Demo-demo14-1.conf"
我还可以看到使用ps -ef在后台运行的子进程,但是这是一个计算/内存密集型工作负载,它似乎并没有真正使用任何cpu或内存让我相信没有真正发生的事情而且它被卡住了。