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

关于 Tornado 中 HTTP 请求的疑问

  •  1
     
  •   leo7476040305 · Aug 25, 2020 via iPhone · 2174 views
    This topic created in 2230 days ago, the information mentioned may be changed or developed.

    在 tornado 中使用 requests, urllib 和自带的 httpclient 都会超时,脱离 tornado 单独使用却没有这个问题,这是怎么回事呢

    ruanimal
        1
    ruanimal  
       Aug 26, 2020
    requests 不支持异步,其他几个应该也是类似的原因。
    ps: 现在这么还有人用 tornado
    neoblackcap
        2
    neoblackcap  
       Aug 30, 2020
    用 tornado 要搞清楚它的原理,你说的那几个底层都是一样的,原理也就是底层 socket 没有设成同步非堵塞,没有将对应的读写时间挂载到 tornado 的时间循环上,那么用起来肯定有一些奇奇怪怪的东西。
    解决方法有好多,这里我说两个
    1. https://github.com/encode/httpx,API 类似 requests,因为是 requests 的封装
    2. 用 tornado 自带的 httpclient,那个是封装底层 libcurl 的,也做过对应的调整,能支持异步请求
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   769 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:50 · PVG 04:50 · LAX 13:50 · JFK 16:50
    ♥ Do have faith in what you're doing.