python 多线程
import threading
from time import sleep
def reste(chapter, chapter_herf, sleeptime):
sleep(sleeptime)
print('===================')
# doSomeThing
# content = get_contents(chapter_herf)
# write_txt(chapter, content, 'utf8')
t1 = threading.Thread(target=reste, args=('parm1', 'parm2', 1))
t1.start()
t2 = threading.Thread(target=reste, args=('parm1', 'parm2', 1))
t2.start()
threading.Thread(target=reste, args=('parm1', 'parm2', 1)).start()
python 线程池
from concurrent.futures import ThreadPoolExecutor
from loguru import logger
def main(i):
logger.info('我是第' + str(i) + '页')
time.sleep(3)
if __name__ == '__main__':
# 10 表示开启10个线程池
with ThreadPoolExecutor(10) as threadPool:
for i in range(1, 683):
threadPool.submit(main, i)
# threading.Thread(target=main, args=[i]).start()