Hello i'm actually trying to append data from a process to a shared list. The Code works and the list is correct at the end. But there are always traceback errors with Errno 9 Bad file descriptor. I'm not a python expert, so i wanted to ask if someone can explain me why it happens and how i can prevent that behavior.
This is the function which appends data to list.
def firstClient(server: str, port: int, result_list):
client = iperf3.Client()
client.duration = 1
client.server_hostname = server
client.port = port
result = client.run()
if result.error:
print(result.error)
else:
### Gibt die Mbit mit 2 nachkommastellen aus
### print kann mit einer variable ersetzt werden für csv implementiereung
print("{:.2f}".format(float(result.received_Mbps)))
result_list.append("List 1 " + "{:.2f}".format(float(result.received_Mbps)))
This is the if name = main for entry points
if __name__ == '__main__':
manager = Manager()
result_cl1 = manager.list()
result_cl2 = manager.list()
result_cl3 = manager.list()
for x in range(10):
clProcess1 = Process(target=firstClient, args=("127.0.0.1",5000, result_cl1))
clProcess2 = Process(target=secondClient, args=("127.0.0.1",5001, result_cl2))
clProcess3 = Process(target=thirdClient, args=("127.0.0.1",5002, result_cl3))
clProcess1.start()
clProcess2.start()
clProcess3.start()
clProcess1.join()
clProcess2.join()
clProcess3.join()
print(result_cl1)
This is the Traceback error
List 3 29837.53
List 1 30292.82
List 2 37211.10
Traceback (most recent call last):
File "/usr/lib/python3.8/multiprocessing/util.py", line 300, in _run_finalizers
finalizer()
File "/usr/lib/python3.8/multiprocessing/util.py", line 224, in __call__
res = self._callback(*self._args, **self._kwargs)
File "/usr/lib/python3.8/multiprocessing/managers.py", line 900, in _decref
tls.connection.close()
File "/usr/lib/python3.8/multiprocessing/connection.py", line 177, in close
self._close()
File "/usr/lib/python3.8/multiprocessing/connection.py", line 361, in _close
_close(self._handle)
OSError: [Errno 9] Bad file descriptor
['22532.42', '31372.60', '39975.43', '38376.93', '50348.28', '35479.34', '34524.44', '46388.68', '30838.45', '30292.82']
As you can see the list is correct and printed so the code works. Anyone know how i can avoid the error ?
Edit: I found which function causes the error, but don't know how to avoid.
result_list.append("{:.2f}".format(float(result.received_Mbps)))
Did i made something wrong ?