Wikipedia icon indicating copy to clipboard operation
Wikipedia copied to clipboard

Add a timeout to all requests

Open manurFR opened this issue 9 years ago • 2 comments

An application using this module can hang indefinitely if, for whatever reason, the HTTP(S) requests are not successful. I had the problem and it is difficult to debug, since there are no errors displayed and the app continues to run without doing anything.

Wikipedia is (smartly) using the Requests framework, but does not follow this advice given in the documentation :

You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter. Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely.

I've added the timeout parameter, with a value of 10 seconds, in the requests.get() call where all the need to fetch data from HTTP converge. At least it rendered my problem manageable by giving me feedback when my requests where stalling.

manurFR avatar Jan 20 '17 14:01 manurFR

I've voluntarily kept this very simple, as I don't know if the project owner wish to add a wikipedia.set_timeout() method and give flexibility to the duration of the timeout.

manurFR avatar Jan 20 '17 14:01 manurFR

It would be really useful if this feature could be added to the code!

theobori avatar Jul 26 '25 19:07 theobori