python multissh pool on windows
Question: Trying to get a process pool to work on windows but after asking me the
password it again asks me the password.

    
    
    import os
    import sys 
    import paramiko
    import getpass
    import socket
    from multiprocessing import Pool
    
    
    def processFunc(hostname):
     handle = paramiko.SSHClient()
     handle.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     handle.connect(hostname, username=user, password=pw)
     print("child")
     stdin, stdout, stderr = handle.exec_command("show clock")
     cmdOutput = ""
     while True:
      try:
     cmdOutput += stdout.next()
      except StopIteration:
      break
      print("Got output from host %s:%s" % (hostname, cmdOutput))
      handle.close()
    
     user = "sup"
     f= open('csip.txt','r')
      hostnames = []
     for line in f:
        hostname = line.strip()
        hostnames.append(hostname)
     pw = getpass.getpass("Enter ssh password:")
    
     if __name__ == "__main__":
         pool = Pool(processes=4)
         pool.map(processFunc, hostnames, 1)
     pool.close()
     pool.join()
    

Am i doing something wrong? The script should read hostnames from the txt file
get the password and then invoke the process pool.


Answer: The below works -

But i want help to improve it. dont want to hardcode the username and
password.

    
    
    import os
    import sys 
    import paramiko
    from multiprocessing import Pool
    
    #Globals
    Hostnames = []
    f= open('csip.txt','r')
    for line in f:
    hname = line.strip()
    Hostnames.append(hname)
    
    
    def processFunc(Hostname):
        handle = paramiko.SSHClient()
        handle.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        handle.connect(Hostname, username="sup", password="123")
        print("child")
        stdin, stdout, stderr = handle.exec_command("show platform | i unknown")
        cmdOutput = ""
        while True:
        try:
            cmdOutput += stdout.next()
        except StopIteration:
            break
    print("Got output from host %s:%s" % (Hostname, cmdOutput))
    handle.close()
    
    
    if __name__ == "__main__":
        pool = Pool(processes=9)
        pool.map(processFunc, Hostnames, 1)
        pool.close()
        pool.join()
    

