Я использую pexpect для входа в систему по нескольким ssh.Мне нужно выполнить несколько отдельных сессий и запустить команды параллельно на одном сервере.Я использовал модуль копирования.но это не работает для меня.Любые предложения приветствуются
пробовал в Ubuntu с pexpect == 4.2.1 paramiko == 2.1.1
import concurrent.futures
import copy
def execute_me(session, cmd):
session.sendline(cmd)
session.expect([':~$', pexpect.TIMEOUT])
print "Printing the session in execute me: \n", session.before, session.after
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
session = pexpect.spawn('ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i /home/ubuntu/keys/X ubuntu@X.X.X.X')
session.sendline('who')
session.expect([':~$', pexpect.TIMEOUT])
print "First print of session;\n", session.before, session.after
future_to_output = {}
cmd = ['ls -lrt', 'uname']
for count in range(2):
future_to_output[executor.submit(execute_me, copy.copy(session), cmd[count])] = count
for future in concurrent.futures.as_completed(future_to_output):
future.result()```
It is using same session, not the copy of session. I mean session is not copyed. Is there any way to copy session in this case?