I am trying to implement a function in an application of Ryu controller. It's like everytime when I receive 7 packets with the same src_ip and dst_ip, they will be written in a pcap file. And then convert this pcap file into a NFstream and do some processing about this NFstream. After this conversion, this pcap file will be deleted and regenerated(filled again) by next 7 packets. But in the runtime, I find that usually the process of writing in this pcap file is delayed, which means the instruction of writing in this pcap file is executed but the pcap file hasn't actually been written. And so NFstream cannot be produced. I try to start a new thread to execute the instruction of writing this pcap and let the main thread wait for its finish. But never worked. Can someone help me to fix this? Thanks in advance
'''
#self.pcap_writer is defined in __init__ as self.pcap_writer =
#pcaplib.Writer(open(pcapfile, 'wb'))
if self.address_paircount[addr_pair] > 7:
for paket in self.address_pair_packetlist[addr_pair]:
t1 = Thread(target=self.pcap_writer.write_pkt(paket))
t1.start()
t1.join()
#sleep(1)
while (not os.path.getsize('fixed_packet_extracted_pcap.pcap')):
print('waiting')
#break
return
pass
-----------------------------------------------------------------
In the middle some processing for this pcap file, and then delete this pcap file and restart the pcaplib.Writer
------------------------------------------------------------------
os.remove('fixed_packet_extracted_pcap.pcap')
self.pcap_writer = pcaplib.Writer(open('fixed_packet_extracted_pcap.pcap', 'wb'))
'''