Reputation: 13
when I use HTTPConnection under python 2.4,if the serve do not answer,the connection is keeped forever.How can i break it?
Upvotes: 1
Views: 766
Reputation: 39869
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).
Upvotes: 1
Reputation: 7380
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.
Upvotes: 2
Reputation: 29727
Use that connection in the separate thread and join it using the desired timeout value.
Upvotes: 0