0
因此,我已经做了一个程序,自动更新人民框,我有这一切工作,然后我回去,并使其多线程,一切工作时,我硬编码线程在我的自我中,现在我想为从文件中读入的每个用户创建一个新线程,我不知道如何为我的程序执行此操作。我的程序的其余部分完成后只需动态地创建线程。我的代码在下面,我评论了我认为线程应该开始的位置。动态在python中为每个用户从文本文件中读取线程
def run(self)
try:
location = "location"
onloc = "onloc"
port = 22
self.Put(location, onloc, self.ThreadIP, self.ThreadPw, self.ThreadUser, port)
re = self.HTTPing("https://%s" %self.ThreadIP)
while not re:
time.sleep(60)
self.HTTPing("https://%s" %self.ThreadIP)
print "Is on"
except:
print ("This ip does not est %s" %self.ThreadIP)
with open("People.txt" , 'r') as inFile:
for line in inFile:
ip,user,password = line.strip().split(',')
""what should i put here to make threads
'MyThreadClass(arguments,go,here).start()'? – Kevin 2014-09-30 13:17:40
你只需要创建你的线程类的实例,传递正确的参数。您也可以将这些实例存储在某种数据结构中。 – tijko 2014-09-30 13:18:28