我总是使用光纤将进程从本地PC部署到远程服务器。如果我有这样的python脚本:test.py:import timewhile True: print "Hello world." time.sleep(1)显然,该脚本是连续运行的脚本。然后,我将此脚本部署到远程服务器并执行我的结构脚本,如下所示:...sudo("python test.py")构造将始终等待test.py的返回并且不会退出。如何立即停止构造脚本并忽略test.py的返回
3 回答

Smart猫小萌
TA贡献1911条经验 获得超7个赞
通常,对于此类异步任务处理,Celery是首选。 这详细说明了芹菜和织物的结合使用。
from fabric.api import hosts, env, execute,run
from celery import task
env.skip_bad_hosts = True
env.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
添加回答
举报
0/150
提交
取消