如何为 urllib2.urlopen 实现超时控制 [英] How to implement a timeout control for urlllib2.urlopen

查看:36
本文介绍了如何为 urllib2.urlopen 实现超时控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Python 中实现对 urllib2.urlopen 的控制?我只是想监控,如果在 5 秒内没有 xml 数据返回,切断这个连接并重新连接?我应该使用一些计时器吗?谢谢

How to implement a controlling for urlllib2.urlopen in Python ? I just wanna monitor that if in 5 seconds no xml data return, cut this connection and connect again? Should I use some timer? thx

推荐答案

urllib2.urlopen("http://www.example.com", timeout=5)

这篇关于如何为 urllib2.urlopen 实现超时控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆