Home  >  Article  >  Backend Development  >  Two parallel method codes of fabric

Two parallel method codes of fabric

高洛峰
高洛峰Original
2017-03-23 14:54:021710browse

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')
   然后  运行 fab -P  backup_and_cp就可以了

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')

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!

Statement:
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