在python3中有concurrent实现多线程工作
import threading
from concurrent.futures import ThreadPoolExecutor
def retrieval_one_query(query, src_line):
pass
def yield_query(query_url_file) -> tuple:
with open(query_url_file, 'r') as file_reader:
line = file_reader.readline()
while line:
line = line.strip()
query = line
yield query, line #yeild 获取值
line = file_reader.readline()
with ThreadPoolExecutor(100) as p:
future_tasks = [
p.submit(retrieval_one_query, q, src_line) for q, src_line in yield_query(query_file)
] #线成列表,开创100个线程,q, src_line是函数retrieval_one_query的参数