[Tutor] how to set time limit before downloading file

Kent Johnson kent37 at tds.net
Thu Aug 24 14:58:01 CEST 2006


kulibin da-da! wrote:
> I had to download some files.
>
>  Using the code below I could download almost all I had to download, but I
>  have a problem with 'http://18wheels.wz.cz/csszengarden/back-con.jpg'
>
> And the problem is that the script sleeps for some hours. And thats
> all - no data is read.
>
>  Can you show me what is wrong and
> 1. how to set time for file downloading after what it will ignore this
> file and start working with next file.
>   
In your loop you could keep track of the total download time and abort 
if it is too long. See time.time().
> 2. how to set time for every "d = r.read(1024)" after what script will
> ignore this file and start working with next file.
>   
Try calling socket.setdefaulttimeout() before any of your network 
operations start.

Kent



More information about the Tutor mailing list