如何防止面料形式等待过程返回

我总是使用光纤将进程从本地PC部署到远程服务器。


如果我有这样的python脚本:


test.py:


import time

while True:

    print "Hello world."

    time.sleep(1)

显然,该脚本是连续运行的脚本。然后,我将此脚本部署到远程服务器并执行我的结构脚本,如下所示:


...

sudo("python test.py")

构造将始终等待test.py的返回并且不会退出。如何立即停止构造脚本并忽略test.py的返回


缥缈止盈
浏览 150回答 3
3回答

Smart猫小萌

通常,对于此类异步任务处理,Celery是首选。 这详细说明了芹菜和织物的结合使用。from fabric.api import hosts, env, execute,runfrom celery import taskenv.skip_bad_hosts = Trueenv.warn_only = True@task()def my_celery_task(testhost):    host_string = "%s@%s" % (testhost.SSH_user_name, testhost.IP)    @hosts(host_string)    def my_fab_task():        env.password = testhost.SSH_password        run("ls")    try:        result = execute(my_fab_task)        if isinstance(result.get(host_string, None), BaseException):            raise result.get(host_string)    except Exception as e:        print "my_celery_task -- %s" % e.message
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python