Python iperf3 get "unable to send cookie to server: "



我有一个简单的python脚本,它可以连续运行iperf3。目前,只有第一个请求有效。第二个请求引发错误"无法将cookie发送到服务器"这是在ubuntu 20服务器上脚本如下:

!/usr/bin/python3
import iperf3
import time
client = iperf3.Client()
client.duration=1
#client.bind_address='172.17.0.2'
#client.server_hostname='192.168.5.108'
client.bind_address='localhost'
client.server_hostname='localhost'
client.port=5201
client.blksize = 1234
client.num_streams = 10
client.zerocopy = True
client.verbose = False
client.reverse = False
while True:
result = client.run()
time.sleep(3)
print(result)

在服务器端,我只是运行iperf3的

iperf3 Python包装器中可能存在错误,导致无法多次运行同一个Client对象。

对我来说,解决方法是在循环中创建一个新的Client,并总是在最后销毁它(以便释放所有资源(:

while True:
client = iperf3.Client()
# set all needed client setting...

result = client.run()
time.sleep(3)
print(result)
del client

注意:运行del client通常会触发即时垃圾收集(取决于特定的Python解释器(,垃圾收集应该运行所需的清理任务。但是,Python GC不能保证立即运行,因此这可能并不总是有效的。您可以考虑手动触发GC。。。

另请参阅有关Github问题的讨论。

相关内容

最新更新