how to time-out gracefully while downloading with python

后端 未结 4 873
面向向阳花
面向向阳花 2021-02-08 11:20

I\'m downloading a huge set of files with following code in a loop:

try:
    urllib.urlretrieve(url2download, destination_on_local_filesystem)
except KeyboardInt         


        
4条回答
  •  春和景丽
    2021-02-08 12:13

    If you're not limited to what's shipped with python out of the box, then the urlgrabber module might come in handy:

    import urlgrabber
    urlgrabber.urlgrab(url2download, destination_on_local_filesystem,
                       timeout=30.0)
    

提交回复
热议问题