Python Made a program , The function is to receive GPS data ,CAN Data and image data , Interface display GPS spot ,CAN Real time data refresh and real-time image display , At the same time, three data are written to the background csv In file , Since the data are independent of each other , therefore GPS Receive and parse I created a thread ,CAN Data receiving and sending create a thread respectively , Image parsing creates a thread , Then all the data are passed through signal.emit Custom signal to csv The writing thread writes .
CANRecThread = threading.Thread(target=self.CANReceiveData)
# Create daemons
CANRecThread.setDaemon(True)
CANRecThread.start()
Run a thread alone , The program can run continuously without problems , But at the same time 3 Data collection threads , It's OK to start running for a while , But it will prompt in a few minutes “Python Has stopped working , Due to problems , The program stops working normally ,Windows The program will be closed , And will notify you when a solution is available ”
my CSV The writing process adds a lock , At present, it seems that the writing timing is correct
threadLock = threading.Lock()
threadLock.acquire()
# Determine which data input , write in csv
threadLock.release()
The initial suspicion is that there are too many threads , High data concurrency , An error is reported because the system memory is exceeded
I made a block diagram , Want to consult colleagues in the industry , For my program block diagram , There is no multithreading , High concurrency , Multithreading frameworks that are not easy to crash can be referred to