2017-06-06 32 views
0

個人名單我有兩個列表中的一個列表中包含的服務器名稱,第二個列表包含兩個列表等於服務list.the長度。如何通過兩個列表,以多重處理目標函數和處理與各個過程

server_list = [u'server1', u'server2', u'sever3', u'server4'] 
servive_name = [[u'postfix', u'diamond', u'lldpd', u'ssh', u'nagios-nrpe-server'], [u'postfix', u'lldpd', u'ssh', u'nagios-nrpe-server'], [u'postfix', u'lldpd', u'ssh', u'nagios-nrpe-server'], [u'postfix', u'lldpd', u'ssh', u'nagios-nrpe-server']] 

我有這個功能

ssh_to_restart(server_name,services,output): 
{ 
// do ssh on the server and restart the service from service list 
} 

我想是每個進程都在服務器名稱,並從各自的列表中的服務列表(EX- Server1上必須與第一個映射列表中SERVICE_LIST和等等)並執行ssh_to_restart()函數。 用它創建的進程號也應該等於server_list的長度。 如何與東西​​做到這一點這樣的代碼

output = multiprocessing.Queue() 
processes = [multiprocessing.Process(target=ssh_to_server, args=(server_list,service_list,output))] 

編輯: -

我試着用這些代碼

from multiprocessing.dummy import Pool as ThreadPool 
pool = ThreadPool(4) 
    pool.map(ssh_to_restart,zip(server_list,service_list)) 
    pool.close() 
    pool.join() 

,但得到這個錯誤

TypeError: ssh_to_restart() takes exactly 2 arguments (1 given) 

回答

0

我做用

解決問題
from multiprocessing.dummy import Pool as ThreadPool 
pool = ThreadPool(4) 
pool.map(ssh_to_restart,zip(server_list,service_list)) 
pool.close() 
pool.join() 

錯誤

TypeError: ssh_to_restart() takes exactly 2 arguments (1 given) 

中加入雙括號中insert_and_process的定義,解決各地

ssh_to_restart((server_name,services,output)): 
{ 
// do ssh on the server and restart the service from service list 
} 

額外的括號 - Python視作爲這應該是一個2項的單個參數序列。該序列的第一個元素是由於所述第一變量,和另一個與第二