|
大家好,
我正在用python写一个下载网易相册的小程序,源代码在这里 。现在遇到一个奇怪的问题。主程序执行到下面这个函数时:
- def download_pic ( pic ):
- """Download picture.
- @todo: need integrity validation and retry facility. (emergent)
- """
- name = pic['name']
- url = pic['url']
- print "download \'"+url+"\' and save as'"+name+"\'. wait...",
- start_time = time.time()
- urllib.urlretrieve(url,name)
- run_time = time.time()-start_time
- print "done! time: %.1f seconds" % run_time
复制代码
速度非常慢,我下载一个80k大小的图片需要花费约15秒的时间。而单独运行这个函数下载同样的图片(其中目录名及文件名由于隐私问题隐去):
>>> import down163
>>> pic
{'url': 'http://img109.photo.163.com/xxxxx/111111111/222222222.jpg', 'name': 'test.jpg'}
>>> down163.download_pic(pic)
download 'http://img109.photo.163.com/xxxxxx/111111111/222222222.jpg' and save as'test.jpg'. wait...
done! time: 0.2 seconds
则如输出信息所示,只需要0.2秒。现在我很迷惑,有谁能指点一下原因啊? |
|