推荐学习书目
› 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
pc10201
V2EX  ›  Python

python 的 requests 库使用异步并处理失败问题?

  •  
  •   pc10201 · Feb 22, 2014 · 11089 views
    This topic created in 4663 days ago, the information mentioned may be changed or developed.
    我找了一下requests本身没有异步功能
    有一个库grequests,但网上就一个范例
    我自己用gevent来写,不过通过 HttpAnalyzer抓包发现请求还是按顺序执行的
    requests官网推荐了一个
    https://github.com/ross/requests-futures
    里面有回调函数
    但现在有一个问题,比如说有50个关键词,要通过异步查排名,但百度推广实况查排名有频率限制,会有很多失败的,这些失败的我如何再去查一次直至全部查完?
    2 replies  •  1970-01-01 08:00:00 +08:00
    tonyseek
    tonyseek
    Feb 22, 2014
    1
    你需要把会发起请求的过程封装成一个函数,然后用 gevent.spawn 调用。这个和多线程是类似的,只在一个 Greenlet 里面当然还是顺序执行的。
    mindcat
    mindcat
    Feb 22, 2014
    2
    用grequests就是了喵~ 不知道怎么用就看测试范例喵
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   854 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:10 · PVG 05:10 · LAX 13:10 · JFK 16:10
    ♥ Do have faith in what you're doing.