Two parallel method codes of fabric

高洛峰
Release: 2017-03-23 14:54:02
Original
1649 people have browsed it

fabric is a python class library. A command line tool based on the ssh protocol is used for application deployment and system task management. Let’s talk about two ways to run fabric code in parallel. Method:

1: Parameter -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')
Copy after login
   然后  运行 fab -P  backup_and_cp就可以了
Copy after login

2: Decorator

import timefrom 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')
Copy after login

Run fab backup_and_cp and it will be OK

The above is the detailed content of Two parallel method codes of fabric. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!