hanerlv
hanerlv

Reputation: 13

How to set the timeout on HTTPConnection under python 2.4

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

Answers (3)

Cyril N.
Cyril N.

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

WeaselFox
WeaselFox

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

Roman Bodnarchuk
Roman Bodnarchuk

Reputation: 29727

Use that connection in the separate thread and join it using the desired timeout value.

Upvotes: 0

Related Questions