Home >Backend Development >Python Tutorial >Two parallel method codes of fabric
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!