Python Forum
fetching exit status hangs in paramiko
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fetching exit status hangs in paramiko
#1
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
Reply
#2
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'?
Reply
#3
print(task) returns list of the commands i mentioned,like
Output:
['\ncommand1;\ncommand2]

Replacing /n with \n returns

Output:
[' ','command1','command2']
Reply
#4
Does it still hang, once each command is a separate item, and after you remove that empty leading task?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,850 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  Fetching the port number using asyncio gary 0 952 Nov-01-2022, 02:53 AM
Last Post: gary
  Fetching data from multiple tables in a single request. swaroop 0 1,906 Jan-09-2021, 04:23 PM
Last Post: swaroop
  ERROR: Command errored out with exit status 1 calesii 3 7,192 Oct-23-2020, 05:39 PM
Last Post: snippsat
  "pip install -e ." returns : ERROR: Command errored out with exit status 1 mostafaPython 3 5,523 Jun-09-2020, 09:28 AM
Last Post: snippsat
  Fetching data from Sklearn zaki424160 2 4,128 Jul-09-2019, 05:20 AM
Last Post: ThomasL
  Error while fetching data from PostgreSQL linu 3 4,327 May-13-2019, 02:38 PM
Last Post: rxndy
  subprocess - get exit status of command run on different machine using rsh prashanth_CM 0 2,199 Sep-25-2018, 07:29 AM
Last Post: prashanth_CM
  Need help to correct my python function for fetching full data! PrateekG 2 2,921 May-27-2018, 06:39 AM
Last Post: PrateekG
  Fetching private ip address from instances of an autoscaling group deepsonune 0 3,277 May-18-2018, 10:32 AM
Last Post: deepsonune

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020