python - How to get download speed elegantly?
天蓬老师
天蓬老师 2017-05-18 10:44:51
0
5
665

I used to use urlopen and then read, open a thread, and detect the received buffer size every second. Is there a more elegant way to gain speed?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(5)
仅有的幸福

For urllib.urlretrieve(url[, filename[, reporthook[, data]]]), write the callback function

import time
import urllib
start_time = time.time()
def Schedule(a,b,c):
    '''
    a:已经下载的数据块
    b:数据块的大小
    c:远程文件的大小
    '''
    speed = (a * b) / (time.time() - start_time)
    print speed
    
urllib.urlretrieve(url,local,Schedule)
Ty80

Use progreebar

曾经蜡笔没有小新

streaming.

我想大声告诉你

Have you tried detecting the increment of the downloaded file?
Check the local size of the downloaded file regularly and take the increment.

曾经蜡笔没有小新

If it is python, most libraries will provide callback functions to do this work.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!