when I use HTTPConnection under python 2.4,if the serve do not answer,the connection is keeped forever.How can i break it?
Asked
Active
Viewed 731 times
3 Answers
2
you can use socket.setdefaulttimeout() and set it to a global timeout
example :
import socket
socket.setdefaulttimeout(30)
now all httplib/urllib2 requests will have a timeout of 30 seconds.
WeaselFox
- 7,100
- 7
- 42
- 73
1
For those who use Python 2.7 and later, HTTPConnection provides a timeout parameter !
httplib.HTTPConnection('www.cwi.nl', 80, timeout=10)
(This doesn't answer this question because the OP asked for Python 2.4, but it can help others looking for that specific answer).
Cyril N.
- 37,442
- 34
- 128
- 228
0
Use that connection in the separate thread and join it using the desired timeout value.
Roman Bodnarchuk
- 28,019
- 11
- 57
- 73