how to time-out gracefully while downloading with python

后端 未结 4 865
面向向阳花
面向向阳花 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:10

    This question is more general about timing out a function: How to limit execution time of a function call in Python

    I've used the method described in my answer there to write a wait for text function that times out to attempt an auto-login. If you'd like similar functionality you can reference the code here:

    http://code.google.com/p/psftplib/source/browse/trunk/psftplib.py

提交回复
热议问题