1

Very occasionally when making a http request, I am waiting for an age for a response that never comes. What is the recommended way to cancel this request after a reasonable period of time?

1
  • What code are you using to make the request? Commented Mar 25, 2009 at 21:18

3 Answers 3

2

Set the HTTP request timeout.

Sign up to request clarification or add additional context in comments.

1 Comment

I must be pretty tired, not to think to look there first, Thanks!
1

The timeout parameter to urllib2.urlopen, or httplib. The original urllib has no such convenient feature. You can also use an asynchronous HTTP client such as twisted.web.client, but that's probably not necessary.

Comments

1

If you are making a lot of HTTP requests, you can change this globally by calling socket.setdefaulttimeout

1 Comment

Thanks, I'm doing this because it seems that the timeout parameter was only added in python 2.6 and I need to support 2.5 as. well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.