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

关于 python 的 timeout 问题,超时即报错

  •  
  •   nankingpython · May 30, 2016 · 4237 views
    This topic created in 3635 days ago, the information mentioned may be changed or developed.

    不管是全局 socket 的设置还是 urllib.request ( urllib2 )都是超时就报错退出程序, 有什么办法解决吗, 谢谢

    jinxueliu
        1
    jinxueliu  
       May 30, 2016   ❤️ 1
    通过异常处理来解决

    import socket
    socket.setdefaulttimeout(10)

    try:

    ....

    except socket.timeout:
    print('Error: time out')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3422 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:53 · PVG 18:53 · LAX 03:53 · JFK 06:53
    ♥ Do have faith in what you're doing.