在 运行 Python 芹菜作为守护进程时无法执行 Ruby 脚本
Can't execute Ruby Script while running Python Celery as Daemon
我有 Python Celery 运行ning 作为守护进程,Celerybeat 在 Amazon Linux 机器上接收任务。当我 运行 我的测试任务时,它顺利完成。
@app.task
def test():
print("Testing 123")
return 0
但是,当我尝试使用 Python 的 subprocess
模块启动 Ruby 脚本时,它会轮询几次,然后以 return 1
.
代码
@app.task
def run_cli():
try:
process = subprocess.Popen([filepath, "run"], stdout=subprocess.PIPE)
while not process.poll():
data = process.stdout.readline()
if data:
sys.stdout.write("Polling: " + data.decode("utf-8"))
else:
sys.stdout.write("Polling: No Data.")
return process.wait()
except Exception as e:
print(e)
我已经确认 Ruby 脚本 运行 由 Celery worker 在 Python shell 中使用 tasks.run_cli.apply()
执行时干净利落。那么为什么 Celery Daemon 不执行这个任务呢?
预警:我是 Python 和 Celery 的新手,我的 Linux 技能参差不齐,如果有明显问题,我深表歉意。非常感谢任何帮助。
为了结束轮询,Ruby 脚本必须将非零信号发送回 Python 脚本,否则该过程将完成并且 Python 继续轮询而不接收数据。也可以在 else 条件下跳出循环,因为对 process.stdout.readline()
的虚假响应表明(我怀疑)脚本处理已完成。
我有 Python Celery 运行ning 作为守护进程,Celerybeat 在 Amazon Linux 机器上接收任务。当我 运行 我的测试任务时,它顺利完成。
@app.task
def test():
print("Testing 123")
return 0
但是,当我尝试使用 Python 的 subprocess
模块启动 Ruby 脚本时,它会轮询几次,然后以 return 1
.
@app.task
def run_cli():
try:
process = subprocess.Popen([filepath, "run"], stdout=subprocess.PIPE)
while not process.poll():
data = process.stdout.readline()
if data:
sys.stdout.write("Polling: " + data.decode("utf-8"))
else:
sys.stdout.write("Polling: No Data.")
return process.wait()
except Exception as e:
print(e)
我已经确认 Ruby 脚本 运行 由 Celery worker 在 Python shell 中使用 tasks.run_cli.apply()
执行时干净利落。那么为什么 Celery Daemon 不执行这个任务呢?
预警:我是 Python 和 Celery 的新手,我的 Linux 技能参差不齐,如果有明显问题,我深表歉意。非常感谢任何帮助。
为了结束轮询,Ruby 脚本必须将非零信号发送回 Python 脚本,否则该过程将完成并且 Python 继续轮询而不接收数据。也可以在 else 条件下跳出循环,因为对 process.stdout.readline()
的虚假响应表明(我怀疑)脚本处理已完成。