问题
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
回答1:
urllib2.urlopen("http://www.example.com", timeout=5)
回答2:
From the urllib2 documentation...
The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This actually only works for HTTP, HTTPS and FTP connections.
来源:https://stackoverflow.com/questions/16018007/how-to-implement-a-timeout-control-for-urlllib2-urlopen