I try to use "join" to manage and stop those threads that cost too much time. And, I use "While" in threads to keep threads always running. However, I find that these threads will never stop. How can I manage a thread that cost too much time? Thank you!
import threading, time
def doThreadTest():
print 'start thread time:', time.strftime('%H:%M:%S')
while 1:
print 1
print 'stop thread time:', time.strftime('%H:%M:%S')
threads = []
for i in range(2):
thread1 = threading.Thread(target=doThreadTest)
# thread1.setDaemon(True)
threads.append(thread1)
for t in threads:
t.start()
for t in threads:
t.join(5) # I use join(5) to stop a thread if it cost more than 5s
print 'stop main thread', time.strftime('%H:%M:%S')