设为首页 加入收藏

TOP

fabric的两种并行方式
2017-10-10 08:28:09 】 浏览:6196
Tags:fabric 并行 方式

fabric是一种python类库,基于ssh协议的命令行工具用于应用部署和系统任务管理,下面来说一下fabric代码并行运行的两种方式:

1:参数  -P

 from fabric.api import *
  host1 = 'root@ip1:22'
  host2 = 'root@ip2:22'
 
  env.hosts = [host1, host2 ]
 
  env.passwords = {
      host1: "p1",
      host2: "p2"
  }                                                                                                                                                                                                                   
  def backup_and_cp():
      with cd("/home/**"):
          run('ls')

 

   然后  运行 fab -P  backup_and_cp就可以了

 

2:装饰器

import time
from fabric.api import *
host1 = 'root@ip1:22'
host2 = 'root@ip2:22'
  env.hosts = [host1, host2 ]
  env.passwords = {
      host1: "p1",
      host2: "p2"
  }
  @parallel                                                                                                                                                                                                                   
  def backup_and_cp():
      with cd("/home/**"):
          run('ls')

运行  fab backup_and_cp就OK了

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇RiceQuant开源项目Rqalpha运行演.. 下一篇格式化字符串format函数

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目