I'm using a thread to run one function of my code, here's a snippet:
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
for addresses in ipa_str_s:
futures.append(executor.submit(checking_connection, ip_address=addresses))
for future in concurrent.futures.as_completed(futures):
save_result = (future.result())
saving_statistics(save_result, saving)
the variable ipa_str_s has a list of IP addresses.
the saving_statistics function, which waits for each call of the checking_connection function to give me the opportunity to save the result.
Called function saving_statistics:
def saving_statistics(save_result, saving):
with open(saving, 'a', encoding='utf-8') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=';')
csv_writer.writerow(['IP-address', 'Packets_transmitted', 'Packets_received'])
csv_writer.writerow(save_result)
if specify the mode a, then get this result:
IP-address;Packets_transmitted;Packets_received
192.168.1.1;3;3
IP-address;Packets_transmitted;Packets_received;
192.168.1.2;3;0
IP-address;Packets_transmitted;Packets_received;
192.168.1.3;3;0
if specify the mode w, then get this result:
IP-address;Packets_transmitted;Packets_received
192.168.1.3;3;0
Could you tell me please, how can I come to the normal content of a file like this:
IP-address;Packets_transmitted;Packets_received
192.168.1.1;3;3
192.168.1.2;3;0
192.168.1.3;3;0
Thank you very much!