Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the timeout value of HTTP

131 views
Skip to first unread message

ken

unread,
Mar 29, 2007, 11:23:00 AM3/29/07
to
Can you please tell me what is the timeout value of httplib.HTTP?

i.e. how long python will wait for a response in the below code?

h = httplib.HTTP(self.url, 8080)
h.putrequest('GET', '/sample/?url=' + self.url)
h.endheaders()

Thank you.

Alex Martelli

unread,
Mar 29, 2007, 11:31:04 AM3/29/07
to
ken <ken.c...@gmail.com> wrote:

HTTP per se does not define any timeout -- if self.url is correctly
resolved by DNS and accepts a TCP connection on port 8080, and then just
hangs forever, you'll be waiting. You can force timeouts yourself by
playing with socket.setdefaulttimeout(...) before you start the HTTP
interaction.


Alex

Facundo Batista

unread,
Mar 29, 2007, 1:07:44 PM3/29/07
to pytho...@python.org
ken wrote:

> i.e. how long python will wait for a response in the below code?
>
> h = httplib.HTTP(self.url, 8080)
> h.putrequest('GET', '/sample/?url=' + self.url)
> h.endheaders()

For ever.

In Py<=2.5, httplib.HTTP doesn't have a timeout, so you have to do
something like:

>>> import socket
>>> socket.setdefaulttimeout(...)
>>> h = httplib.HTTP(...)

Beware that *all* sockets created after the call to setdefaulttimeout()
will have that default.

httplib.HTTP now has a timeout, but in the development trunk (you'll
have to checkout the SVN code and compile Python yourself, or wait until
Py2.6).

Regards,

--
. Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


0 new messages