2

In the following code, is the connection to the remote server held open until close() is called or is it recreated every time read() is called? In the following code I do see a new network communication happens every time read() is called, rather than the remote file being buffered as soon as urlopen() is called.

import urllib2

handle = urllib2.urlopen('http://download.thinkbroadband.com/5MB.zip')
while True:
    buff = handle.read(64*1024) # Is a new connection to the server created here?
    if len(x) == 0:
        break
handle.close()
Matty
  • 33,203
  • 13
  • 65
  • 93

1 Answers1

0

Try running wireshark or fiddler and look at port 80 with nothing else running. Run your program and see what traffic you get. Should answer your question.

danseery
  • 486
  • 2
  • 11