q = queue.Queue()
with open('all_id.txt', 'r') as f:
for shop_id in f:
q.put(shop_id.strip())
class WorkerThread(threading.Thread):
def run(self):
while True:
# 从队列中获取任务
shop_id = q.get()
if shop_id is None:
q.put(None)
break
# 执行任务
thread_name = '线程: -{}-开始运行.'.format(str(shop_id))
t = threading.Thread(target=get_shop_info, args=(thread_name,shop_id))
t.start()
t.join()
#标记任务完成
q.task_done
threads = []
for i in range(10):
t = WorkerThread()
t.start()
threads.append(t)
t.join()
q.put(None)
for t in threads:
t.join()