fetching exit status hangs in paramiko - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: fetching exit status hangs in paramiko (/thread-38833.html) |
fetching exit status hangs in paramiko - saisankalpj - Nov-29-2022 Hi, I am using paramiko library to run interactive shell. As per my requirement ,I needed to execute a command (say command3) only after executing command1 and command2 parallely.So below is my code to do same ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(HOSTNAME, port=PORT, username=USERNAME, password=PASSWORD) connection = ssh.invoke_shell() connection.send("cd /opt \n") commands = """ command1 command2 """ #Parallel execution of command1 and command2 task = [command for command in commands.split('/n')] with concurrent.futures.ThreadPoolExecutor() as executor: executor.map(connection.send, task) time.sleep(1) result1=connection.recv(600000) time.sleep(1) result=connection.recv_exit_status() print(result) #If command1 and command2 are successful ,then here i need to run command3 time.sleep(1) ssh.close()But my above code doesnt print anything and i am not receiving any response.The code is hanging. How do i proceed now? Thanks RE: fetching exit status hangs in paramiko - nilamo - Dec-02-2022 Quote:task = [command for command in commands.split('/n')] What do you see if you add print(task) right after that?What if you replace '/n' with '\n' ?
RE: fetching exit status hangs in paramiko - saisankalpj - Dec-03-2022 print(task) returns list of the commands i mentioned,like Replacing /n with \n returns
RE: fetching exit status hangs in paramiko - nilamo - Dec-04-2022 Does it still hang, once each command is a separate item, and after you remove that empty leading task? |