gpt4 book ai didi

ruby - 将 Python Celery 作为守护进程运行时无法执行 Ruby 脚本

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:49:47 34 4
gpt4 key购买 nike

我让 Python Celery 作为守护进程运行,Celerybeat 在 Amazon Linux 机器上接收任务。当我运行我的测试任务时,它顺利完成。

@app.task
def test():
print("Testing 123")
return 0

但是,当我尝试使用 Python 的 subprocess 模块启动 Ruby 脚本时,它会轮询几次,然后退出并返回代码 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)

我已经确认,当 Celery 工作人员使用 tasks.run_cli.apply() 在 Python shell 中执行时,Ruby 脚本可以正常运行。那么为什么 Celery Daemon 不执行这个任务呢?

预先警告:我是 Python 和 Celery 的新手,而且我的 Linux 技能参差不齐,所以如果有明显问题,我深表歉意。非常感谢任何帮助。

最佳答案

要结束轮询,Ruby 脚本必须将非零信号发送回 Python 脚本,否则该过程将完成并且 Python 将继续轮询而不接收数据。也可以在 else 条件下跳出循环,因为对 process.stdout.readline() 的虚假响应表明(我怀疑)脚本处理已完成。

关于ruby - 将 Python Celery 作为守护进程运行时无法执行 Ruby 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32939754/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com