Reputation: 69
I use pexpect
's pxssh
model wrote an auto ssh login program.
but when i use the same program in multiprocessing
, this error occurs:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/zenoss/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "/usr/local/zenoss/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/zenoss/lib/python2.6/multiprocessing/pool.py", line 259, in _handle_results
task = get()
TypeError: ('__init__() takes exactly 2 arguments (1 given)', <class 'pexpect.EOF'>, ())
import pxssh
import multiprocessing
class ssh_linux:
def __init__(self,q_host,linux_user,linux_pwd,linux_su_passwd,linux_port):
timeout=5
status,shell=self.ssh_login(q_host,linux_user,linux_pwd,timeout,linux_port)
#i think this error--------
if status:
print 'conn ok!'
self.set_env(shell)
def ssh_login(self,q_host,linux_user,linux_pwd,timeout,linux_port):
status=0
try:
s = pxssh.pxssh()
s.login (q_host,linux_user,linux_pwd,port=linux_port,auto_prompt_reset=True,login_timeout=timeout)
status=1
except pxssh.ExceptionPxssh, e:
s=str(e)
print "ssh login fail!",s
status=0
return status,s
def do_calculation(data):
run=ssh_linux(q_host,linux_user,linux_pwd,linux_su_passwd,linux_port)
def main():
pool_size = multiprocessing.cpu_count() * 2
pool = multiprocessing.Pool(processes=pool_size,initializer=start_process,)
pool.map(do_calculation,input_list)
pool.close()
pool.join()
Upvotes: 2
Views: 522
Reputation: 69
thanks everyone. I found solve this.
this problem is my:Code does not regulate I change my code to this,the return is OK:
self.hostname = q_host
self.username = linux_user
self.password = linux_pwd
self.su_pw=linux_su_passwd
self.port=linux_port
status,shell=self.ssh_login(self.hostname,self.username,self.password,self.timeout,self.port)
Upvotes: 1