gpt4 book ai didi

python - urllib2.urlopen() 创建的对象是否代表一个常量连接?

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:29 25 4
gpt4 key购买 nike

在下面的代码中,与远程服务器的连接是在调用 close() 之前保持打开状态,还是在每次调用 read() 时都重新创建?在下面的代码中,我确实看到每次调用 read() 时都会发生新的网络通信,而不是在调用 urlopen() 时立即缓冲远程文件。

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()

最佳答案

尝试运行 wireshark 或 fiddler 并在没有其他运行的情况下查看端口 80。运行你的程序,看看你得到了什么流量。应该回答你的问题。

关于python - urllib2.urlopen() 创建的对象是否代表一个常量连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com