在做python多线程的时候(threading)
使用了.join()
可是程序执行完毕还是不能自主退出
求解
#!/usr/bin/python
# -*- coding: utf-8 -*-
#encoding=utf-8
#Filename:robot.py
import threading
import Queue
#
# 变量设置
#
THREAD_LIMIT = 3#设置线程数
jobs = Queue.Queue()#设置队列长度
urls = []
for i in range(50):
urls.append(i)
class spider(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while True:
job = self.queue.get()
print job
self.queue.task_done()
if __name__ == '__main__':
print urls
for x in urls:
jobs.put(x)
for i in range(5):
t = spider(jobs)
t.start()
jobs.join()