整理下python多线程的方法,持续更新
ThreadPool 线程池方法
1 2 3 4 5 6 7 |
from multiprocessing.dummy import Pool as ThreadPool pool = ThreadPool(10) # 10个线程 results = pool.map(lambda x: x, urls) # urls是任务列表 list,第一个参数是线程函数 # close the pool and wait for the work to finish pool.close() pool.join() # 最后得到的results,为各个线程的返回结果 |
Thread Class类 方法
汤不热爬虫项目:先收藏以后学习整理下:https://github.com/dixudx/tumblr-crawler/blob/master/tumblr-photo-video-ripper.py