我有几百盒只能用不同的网关访问,如下面所示:如何在使用多处理时将env.host转换为结构?
gateway1:ip1,ip2
gateway2:ip3,ip4 ...
所有作业不需要在一分钟内完成的,所以我在下面使用下面的命令fab -f ytj_sto.py doitnow
多进程,错误。
[]
None
None
***Warning*** Host None via ssh is down
代码:
@parallel(pool_size=20)
def coll():
print env.hosts
print env.host
print env.gateway
if _is_ssh_ok(env.host):
d = patt()
def doitnow():
p=Pool(20)
with open('ytj_sto.hn','r') as f:
for line in f.readlines():
line = line.strip()
if not len(line) or line.startswith('#'):
continue
env.gateway = line.split(':')[0]
env.hosts = line.split(':')[1].split(',')
result = p.apply_async(coll, args=())
result.get()
p.close()
p.join()
编辑: 我用FAB -H -g解决这个问题,感谢所有
def fabfun(Hosts,Gate,des,func1):
with settings(hide('running'), warn_only=True):
local(("fab -H %s -g %s -f %s %s ") % (Hosts,Gate,des,func1))
p=Pool(20)
starttime = time.asctime(time.localtime(time.time()))
print('Waiting for all job done...%s' % starttime)
with open('ytj_sto.hn','r') as f:
for line in f.readlines():
line = line.strip()
if not len(line) or line.startswith('#'):
continue
Hosts = line.split(':')[1]
Gate = line.split(':')[0]
p.apply_async(fabfun, args=(Hosts,Gate,des,func1))
p.close()
p.join()
在哪里布任务('patt')你想打电话?你是如何实现'_is_ssh_ok'的? – 2ps