手机
当前位置:查字典教程网 >脚本专栏 >python >Python中为feedparser设置超时时间避免堵塞
Python中为feedparser设置超时时间避免堵塞
摘要:python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些b...

python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些badurl,经常会导致堵塞,因此需要为feedparser设置一个超时时间。

可是feedparser并没有提供这个功能,只好采用其他方法了,具体办法请参看feedparser项目的issue221。

其实也很简单,按照上面文档的说明

developers have had the ability to set a global timeout for over seven years by importing the socket library and setting the timeout in this way:

复制代码 代码如下:

import socket

socket.setdefaulttimeout(<timeout in floating seconds>)

【Python中为feedparser设置超时时间避免堵塞】相关文章:

python中关于日期时间处理的问答集锦

python中stdout输出不缓存的设置方法

Python 字符串操作方法大全

Python中使用 Selenium 实现网页截图实例

python设置检查点简单实现代码

Python时区设置方法与pytz查询时区教程

Python中的魔法方法深入理解

Python代理抓取并验证使用多线程实现

python检测lvs real server状态

Python中使用中文的方法

精品推荐
分类导航