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

Python新手请教timeout问题~

  •  
  •   VeryCB ·
    VeryCB · Jun 28, 2012 · 4335 views
    This topic created in 5217 days ago, the information mentioned may be changed or developed.
    用douban-python在做一个基于豆瓣API的应用,用下面的代码说一下问题:



    由于网络问题,请求经常会发不出去或者收不到response,也就是有时候运行到 feed = client.GetContacts(url) 就卡住了,看了一下douban-python提供的 GetContacts() 函数,好像也没有提供timeout参数,但是我想如果一次请求20秒还没有收到请求的话,就放弃请求并继续执行程序,请问如何实现?感谢!
    2 replies  •  1970-01-01 08:00:00 +08:00
    VeryCB
        1
    VeryCB  
    OP
       Jun 28, 2012
    写错了,是“一次请求20秒还没有收到回复”
    for4
        2
    for4  
       Jun 28, 2012
    没看过douban-python.
    试试这个? socket.setdefaulttimeout(20)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3049 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:58 · PVG 20:58 · LAX 05:58 · JFK 08:58
    ♥ Do have faith in what you're doing.