Celery守护进程不允许有孩子

时间:2015-11-16 21:05:57

标签: python celery fabric

我正在尝试将Fabric任务与celery任务集成,并遇到了以下问题

这是我的面料demo.py

from fabric.api import env, run, execute, sudo
from fabric.network import ssh

env.user="user"
env.password="mypassword"
#env.parallel=True

class FabricSupport:
    def __init__(self):
        pass

    def hostname(self):
        run("hostname")

    def ls(self):
        #sudo('ls -l', shell=False)
        run("touch test.txt")

    def execute(self,task,hosts):
        get_task = "task = self.%s" % task
        exec get_task
        execute(task,hosts=hosts)

代码本身并行工作

但是当我尝试从celery tasks.py调用它时,我得到了守护进程没有孩子

from demo import FabricSupport
from celery import Celery
from fabric.api import env, run, execute
from fabric.network import ssh, disconnect_all
from celery import Celery
import time

app = Celery('tasks', backend = 'amqp', broker = 'amqp://')

hosts = ['localhost','127.0.0.1']

@app.task()
def run_me():
    myfab = FabricSupport()
    myfab.execute("hostname",hosts)

def main():
    result = run_me.delay()
    print(result.ready())
    while(result.ready() == False):
        time.sleep(5)
    print(result.get())


if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:0)

发现了什么问题。我使用的是台球的最新版本(撰写本文时为3.3.0.21)。它是用pip安装芹菜自动安装的。卸载并安装3.3.0.20,现在一切正常。