V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
axiuluolaitext
V2EX  ›  Python

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

  •  
  •   axiuluolaitext · 2020-06-10 19:38:54 +08:00 · 2033 次点击
    这是一个创建于 1432 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    #!/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)
    
    4 条回复    2020-06-11 08:39:25 +08:00
    cz5424
        1
    cz5424  
       2020-06-10 20:00:07 +08:00 via iPhone
    大家快来帮我写需求,写完了我就可以下班了
    cz5424
        2
    cz5424  
       2020-06-10 20:02:39 +08:00 via iPhone
    把 get 设置个超时
    axiuluolaitext
        3
    axiuluolaitext  
    OP
       2020-06-10 20:27:03 +08:00
    @cz5424 3q 已解决
    MarkLeeyun
        4
    MarkLeeyun  
       2020-06-11 08:39:25 +08:00
    爬虫啊,啊哈哈哈哈。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2832 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:45 · PVG 19:45 · LAX 04:45 · JFK 07:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.