On 06/09/2015 06:17 PM, Javier Barroso wrote:
Hello,
Sorry if you dont want to be in "to" ..
El 9/6/2015 10:44 a. m., "mudongliang" <mudonglianga...@hotmail.com
<mailto:mudonglianga...@hotmail.com>> escribió:
>
> I wonder whether this is a bug for python urllib2.
> The following is the code I used:
>
> target = protocol + "://" + location + directory + target_file
> start = datetime.now()
> try:
> urlrequest = urllib2.Request(target)
> urlresponse = urllib2.urlopen(urlrequest, timeout=4)
>
> urldata = urlresponse.read()
>
> except (urllib2.URLError, socket.timeout):
> return "ERR"
>
> stop = datetime.now()
> time_difference = stop - start
> print("\ntime diff is " + str(time_difference.total_seconds()))
>
> According to the definition of socket.timeout, time_difference will
> be no more than 4 seconds or no part of output.
I think timeout is refering to connection timeout. Ser at doc of urlopen:
"The optional /timeout/ parameter specifies a timeout in seconds for
blocking operations like the connection attempt (if not specified, the
global default timeout setting will be used). This actually only works
for HTTP, HTTPS and FTP connections."
Regards
The document said "blocking operations like the connection attempt", but
it did not say it only covers this time break!
And I think this timeout should be the whole time :connection , transfer
data and so on!
Besides, the experiment on this page
(http://www.01happy.com/python-request-url-set-timeout/) is a proof! It
will cover the whole time break.
mudongliang