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
VeryCB
V2EX  ›  Python

Python新手请教timeout问题~

  •  
  •   VeryCB ·
    VeryCB · 2012-06-28 22:33:15 +08:00 · 3531 次点击
    这是一个创建于 4320 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用douban-python在做一个基于豆瓣API的应用,用下面的代码说一下问题:



    由于网络问题,请求经常会发不出去或者收不到response,也就是有时候运行到 feed = client.GetContacts(url) 就卡住了,看了一下douban-python提供的 GetContacts() 函数,好像也没有提供timeout参数,但是我想如果一次请求20秒还没有收到请求的话,就放弃请求并继续执行程序,请问如何实现?感谢!
    2 条回复    1970-01-01 08:00:00 +08:00
    VeryCB
        1
    VeryCB  
    OP
       2012-06-28 22:36:18 +08:00
    写错了,是“一次请求20秒还没有收到回复”
    for4
        2
    for4  
       2012-06-28 22:40:10 +08:00
    没看过douban-python.
    试试这个? socket.setdefaulttimeout(20)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2521 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:55 · PVG 23:55 · LAX 08:55 · JFK 11:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.