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