def execute_on_host((hostname, command), username=config['username'], keyfile=config['keyfile']):
print hostname
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=hostname, username=username, key_filename=keyfile)
stdin, stdout, stderr = ssh_client.exec_command(command)
print stdout.read()
ssh_client.close()
return stdout
因此,在打印hostname
and之后stdout.read()
,我会收到这样的错误
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 99, in worker
put((job, i, result))
File "/usr/lib/python2.7/multiprocessing/queues.py", line 390, in put
return send(obj)
PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed
我正在使用以下代码来执行命令。
from multiprocessing import Pool
pool = Pool(len(host_cmds_list))
pool.map(execute_on_host, host_cmds_list)
pool.close()
pool.join()
我不知道如何解决这个问题。
print host_cmds_list
[('hostname1', '/bin/date'), ('hostname2', '/bin/date')]