try:
r = requests.get(url, params={'s': thing})
except requests.ConnectionError, e:
print e #should I also sys.exit(1) after this?
Run Code Online (Sandbox Code Playgroud)
它是否正确?有没有更好的方法来构建它?这会涵盖我的所有基础吗?
我正在调用Python中的一个函数,我知道它可能会停止并迫使我重新启动脚本.
如何调用该函数或我将其包装成什么,以便如果它花费的时间超过5秒,脚本会取消它并执行其他操作?
我在urllib2的urlopen中使用了timeout参数.
urllib2.urlopen('http://www.example.org', timeout=1)
Run Code Online (Sandbox Code Playgroud)
如何告诉Python如果超时到期,应该引发自定义错误?
有任何想法吗?