【发布时间】:2016-05-04 09:48:36
【问题描述】:
我在一个名为urlopen_test() 的函数中使用urllib.urlopen()。在这个函数中,我调用了 urlopen 两次,第一次调用很快,第二次就不行了。有人打电话帮我弄清楚原因吗?
顺便说一句,我使用line_profile检查函数中的每一行,结果如下。
Line # Hits Time Per Hit % Time Line Contents
5 @profile
6 def urlopen_test():
7 1 28690 28690.0 0.1 fh =urllib.urlopen('ftp://a.com/1.log')
8 1 58 58.0 0.0 print fh.read()
9
10 1 30027787 30027787.0 99.9 fh = urllib.urlopen('ftp://a.com/1.log')
11 1 40 40.0 0.0 print fh.read()
【问题讨论】: