推荐学习书目
› 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 · Jun 10, 2020 · 2791 views
    This topic created in 2340 days ago, the information mentioned may be changed or developed.

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

    #!/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 replies  •  2020-06-11 08:39:25 +08:00
    cz5424
    cz5424
    Jun 10, 2020 via iPhone
    1
    大家快来帮我写需求,写完了我就可以下班了
    cz5424
    cz5424
    Jun 10, 2020 via iPhone
    2
    把 get 设置个超时
    axiuluolaitext
    axiuluolaitext
    OP
    Jun 10, 2020
    3
    @cz5424 3q 已解决
    MarkLeeyun
    MarkLeeyun
    Jun 11, 2020
    4
    爬虫啊,啊哈哈哈哈。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2283 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:18 · PVG 20:18 · LAX 04:18 · JFK 07:18
    ♥ Do have faith in what you're doing.