Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中从文本文件读入的每个元素的新线程_Python_Multithreading_Python Multithreading - Fatal编程技术网

python中从文本文件读入的每个元素的新线程

python中从文本文件读入的每个元素的新线程,python,multithreading,python-multithreading,Python,Multithreading,Python Multithreading,好的,我有一个程序,是完全功能,但我想多线程它,使它更快,它所做的是更新一个框。现在它一次做一个盒子,我想同时做所有的。我对此做了一些研究,但没有什么能真正帮助我。下面是我的代码 def createSSHClient(self,host,port,user,password): try: client = paramiko.SSHClient() client.load_system_host_keys() client.s

好的,我有一个程序,是完全功能,但我想多线程它,使它更快,它所做的是更新一个框。现在它一次做一个盒子,我想同时做所有的。我对此做了一些研究,但没有什么能真正帮助我。下面是我的代码

 def createSSHClient(self,host,port,user,password):
       try:
         client = paramiko.SSHClient()
         client.load_system_host_keys()
         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
         client.connect(host, port, user, password)
         return client
       except:
          print "could not connect"
          return "nothing"

 def Put(self,location, onloc, host, password, user, port):
      try:                                   
         ssh = self.createSSHClient(host, port, user, password)
         scp = SCPClient(ssh.get_transport())
         scp.put(location,onloc)
         print("Finshed Transfer")
         stdin , stdout, stderr = ssh.exec_command("path")
         print "going to start reboot"
         stdin,stdout,stderr = ssh.exec_command("path")
     except:    
         print "Lost connection"

 def push(self, Filename):
     location = Filename
     onloc = "/remote location"
     port = 22
     ct = 1
     with open("People.txt" , 'r') as inFile:    """Here is where will read in how many threads"""
           for line in inFile:
               ip,user,password = line.strip().split(',')
               self.Put(location,onloc,ip,password,user,port) """Here is where each thread should call"""
               print ("i finshed %d", ct)
               ct=+1

因此,在我的评论中,我展示了我从哪里获得线程,以及我希望线程调用到哪里,有人能帮助我吗。

出于好奇,你看过布料吗?它内置了一定程度的并行化,并且已经为您做了很多连接管理。我可以使用它,但我想了解更多关于python的信息,我几周前刚开始学习,我想了解一些基本的多线程技术。那么您有线程/多处理代码吗?我会从一些示例开始,问您在实现它时是否遇到一些问题。如果您已经知道要在何处生成线程,是什么阻止了您尝试它并了解它的运行情况?看看模块的示例,它显示了在每个操作都是独立的情况下,将类似这样的事情并行化是多么容易,除了初始参数和返回值之外,不需要任何通信。如果您不使用3.2+,则PyPI上会出现一个错误。如果您尝试了这一步,但遇到了问题,请下次显示您尝试了什么,但不要显示您的全部代码,只显示一个示例以及您遇到的问题。