如何在多线程程序中实现超时?

时间:2017-02-17 22:39:19

标签: python multithreading timeout

我有这个示例代码:

import threading
from Queue import Queue
q = Queue(maxsize=0)
def work(q):
    #do a job
for line in file_of_100_line:
    q.put(line)
nbThreads = 2
for i in range(nbThreads):
    t = threading.Thread(target=work, args=(q))
    t.setDaemon(True)
    t.start()

如果线程超过" x"我希望线程结束。秒执行。我怎么能用多线程做到这一点?感谢

0 个答案:

没有答案