How do I stop a for loop in a thread in Python 2.7 ?
Is it possible to stop/continue script while using threading in a for loop ?
from threading import Thread
from Queue import Queue
q = Queue()
items=open('items.txt','r').read().splitlines()
def action():
while True:
开发者_开发问答 item = q.get()
print item
q.task_done()
if __name__=='__main__':
for i in range(10):
t = Thread(target=action)
t.daemon=True
t.start()
for item in items:
q.put(item)
q.join()
精彩评论