写了一个检测网站服务器的脚本跑着跑着就不跑了,刚开始线程多大跑多快!到后来就会越来越慢,在到最后直接不跑了!怎么能解决?谢谢大佬们!代码如下
#!/usr/bin/python3
import requests
import time
from multiprocessing import Pool
def server(url):
try:
url1=url.strip()
res=requests.get(url=url1)
res2 = (res.headers['Server'])
if "Apache" in res2:
print("该网址是 Apache:{0}".format(url.strip()))
f=open("apache.txt","a")
f.write(url.strip()+"\n")
f.close()
else:
print("其他站点")
fx=open("noapache.txt","a")
fx.write(url.strip()+"\n")
fx.close()
except:
print("网络")
fb=open("no1.txt","a")
fb.write(url.strip()+"\n")
fb.close()
if __name__=="__main__":
urls = ['{}'.format(str(i)) for i in open("urls.txt")]
pool = Pool(processes=20)
pool.map(server, urls)