import time
from concurrent.futures import ThreadPoolExecutor
from functools import partial
from loguru import logger
max_items = 2
def gen():
for i in range(30):
yield i
def all_review_demo(url,m="Data"):
logger.info("in all_review_demo")
print(m,url)
PREFIX = "demo"
geno_bj = gen()
m=2
while True:
try:
l = [next(geno_bj) for i in range(5)]
start = time.time()
with ThreadPoolExecutor(max_workers=5) as pool:
try:
pool.map(partial(all_review_demo,m=m), l)
except Exception as e:
logger.info(f"{PREFIX}--出现错误,错误原因:{e.args}")
end = time.time() - start
if end < 1:
wait =1-end
logger.info("等待",wait)
time.sleep(1 - end)
except StopIteration as e:
break