python 如何控制多线程数量
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 如何控制多线程数量相关的知识,希望对你有一定的参考价值。
参考技术A import requests, timefrom threading import Threadclass MyThread(Thread):def __init__(self, url):
Thread.__init__(self)
self.url = url def run(self):
open_url(self.url)def open_url(url):
r = requests.get(url[:-1])
print(r.status_code)
print(url) # return urlif __name__ == '__main__': with open("E:/all_domain.txt",'r') as f:
t_start = time.time()
threads = [] for url in f:
t = MyThread(url)
threads.append(t)
t.start()
print(len(threads)) for i in threads:
i.join()
t_end = time.time()
print('the thread way take %s s' % (t_end - t_start))
以上是关于python 如何控制多线程数量的主要内容,如果未能解决你的问题,请参考以下文章