Closed machoog546 closed 5 years ago
Side thing I just tried. If I run both functions as their own scripts it prints out with no error. Might be threading related?
import iperf3, time import multiprocessing as mp
def client_side(cli, serv, port, YesNo):
if YesNo:
f = open("port_" + str(port) + ".txt", "w+")
traffic=iperf3.Client()
traffic.duration=90
traffic.bind_address=cli
traffic.server_hostname = serv
traffic.port=port
traffic.bandwidth = 180000000
result = traffic.run()
time.sleep(2)
if YesNo:
result = str(result)
time.sleep(1)
f.write(result)
f.close() #Not needed but i want to make sure it saves
clients = [6969, 6970,6971,6971] #not needed. can be put in the args space of the MP call
threads =[] print("starting") c1 = mp.Process(target=client_side, args=("192.168.201.10", "192.168.201.20", clients[0], True,))#, daemon = True) threads.append(c1) c2 = mp.Process(target=client_side, args=("192.168.202.10", "192.168.202.20", clients[1], True,))#, daemon = True) threads.append(c2) c3 = mp.Process(target=client_side, args=("192.168.203.10", "192.168.203.20", clients[2], True,))#, daemon = True) threads.append(c3) c4 = mp.Process(target=client_side, args=("192.168.204.10", "192.168.204.20", clients[3], True,))#, daemon = True) threads.append(c4)
print(threads) for thread in threads: print("Starting " + str(thread)) thread.start() time.sleep(2)
for thread in threads:
thread.join()
time.sleep(1)
print("Complete")
When running the code below if I don't assign the client.run() to a variable it will print to screen like normal. If I assign to a variable to parse it/print later I get the below error.
Error:
Could it be it's seeing an extra character at the start of the list when it does the JSON formatting and it errors out? I know just enough about the JSON to get myself in trouble.
I also changed my json_output=False like in #38 but that causes it to hang. Was hoping for the NoneType, or for something different, but it wasn't the different I was expecting.