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

标签 ruby linux celery daemon python-3.5

我让 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/

相关文章:

python - 从多个 celery worker 登录到一个文件安全吗?

windows - 是否可以通过快捷方式启动 2 个程序?

Ruby:将美元(字符串)转换为美分(整数)

ruby-on-rails - 在 gemfile 中使用 bcrypt 不允许我重新启动 rails 服务器,删除它会导致浏览器出现问题(要求我将其添加回去)

ruby-on-rails - 使用 token_authenticateable 时,使用多个范围登录的用户设计日志,除了一个之外

linux - 为什么linux(x86_64)中的thread_info结构被0填充?

linux - 使用 Ansible CLI/Ad-Hoc 注册变量输出

python - Telebot + Celery + pytransitions : response to task

node.js - RabbitMQ 的 node-celery 与 node-amqp

ruby-on-rails - "Could not find concurrent-ruby-1.1.7 in any of the sources"使用 capistrano 部署 rails