2

I use urllib.urlopen() in a function called urlopen_test(). In this function I call urlopen twice,the first call is quite fast but not the second one. Anyone call help me figure out why?

BTW, I use line_profile inspect every line in the function, following is the result.

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()
fireboy
  • 29
  • 5

1 Answers1

1

I find the point. When I call fh.close() after the first fh.read(), the urlopen_test() function runs fast. But I still don't understand why when I close the file returned by the first urlopen call the second urlopen() runs really fast.

fireboy
  • 29
  • 5