程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python multithreading caused Python to stop working. Due to problems, the program stopped working normally

編輯:Python
The phenomenon and background of the problem
 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 .

establish CAN Data receiving thread mode

CANRecThread = threading.Thread(target=self.CANReceiveData)
# Create daemons
CANRecThread.setDaemon(True)
CANRecThread.start()

Operation results and error reporting contents

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 solution ideas and tried methods

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

What I want to achieve

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved