This article introduces the two parallel methods of fabric. the code fabric is a python class library. the command line tool based on the ssh protocol is used for application deployment and system task management, the following describes two ways to run fabric code in parallel:
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')
Run 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.
These are the details of fabric's two parallel method codes. For more information, see other related articles in the first PHP community!