0

I have a simple python script that continuously runs iperf3. Currently, only the first request works. The second request throws an error 'unable to send cookie to server' This is on an ubuntu 20 server The script is as follows:

!/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)

On the server side I just run iperf3 -s

Tommie Jones
  • 957
  • 1
  • 16
  • 37

1 Answers1

0

There might be a bug in the iperf3 Python wrapper that prevents running the same Client object multiple times.

What worked for me as a workaround is to create a new Client inside the loop and always destroy it at the end (in order to free all resources):

while True:
    client = iperf3.Client()

    # set all needed client setting...
    
    result = client.run()
    time.sleep(3)
    print(result)

    del client

NOTE: Running del client usually triggers immediate garbage collection (depending on specific Python interpreter) which should run needed cleanup tasks. However, Python GC is not guaranteed to run immediately, so this might not always work. You might consider trigerring GC manually...

See also related Github issue discussion.

betatester07
  • 667
  • 8
  • 16