Python 脚本跑着就不跑了,求大佬帮忙解决

2020-06-10 19:38:54 +08:00
 axiuluolaitext

写了一个检测网站服务器的脚本跑着跑着就不跑了,刚开始线程多大跑多快!到后来就会越来越慢,在到最后直接不跑了!怎么能解决?谢谢大佬们!代码如下

#!/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)
2036 次点击
所在节点    Python
4 条回复
cz5424
2020-06-10 20:00:07 +08:00
大家快来帮我写需求,写完了我就可以下班了
cz5424
2020-06-10 20:02:39 +08:00
把 get 设置个超时
axiuluolaitext
2020-06-10 20:27:03 +08:00
@cz5424 3q 已解决
MarkLeeyun
2020-06-11 08:39:25 +08:00
爬虫啊,啊哈哈哈哈。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/680443

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX