From 0da545d9c7e48893ec61addb884a58893c7b54a0 Mon Sep 17 00:00:00 2001 From: csrichter Date: Thu, 11 May 2017 14:12:06 +0200 Subject: [PATCH] added db mutex --- python/tmc_parser.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/tmc_parser.py b/python/tmc_parser.py index 3d70cbc..3ade07b 100644 --- a/python/tmc_parser.py +++ b/python/tmc_parser.py @@ -59,6 +59,7 @@ class tmc_parser(gr.sync_block): db_name=workdir+'RDS_data'+datetime.now().strftime("%Y%m%d_%H%M%S")+'_TMC.db' db=sqlite3.connect(db_name, check_same_thread=False) self.db=db + self.dbLock=QtCore.QSemaphore(1) #create tables try: @@ -97,8 +98,12 @@ class tmc_parser(gr.sync_block): self.save_data() print("closing tmc display") def save_data(self): + #if self.debug: + # print("saving data") if self.writeDB: + self.dbLock.acquire(1) self.db.commit() + self.dbLock.release(1) f=open(self.workdir+'google_maps_markers.js', 'w') markerstring=self.tmc_messages.getMarkerString() markerstring+='\n console.log("loaded "+markers.length+" markers")' @@ -108,11 +113,13 @@ class tmc_parser(gr.sync_block): def print_tmc_msg(self,tmc_msg): if self.writeDB and tmc_msg.event.is_cancellation == False: try: + self.dbLock.acquire(1) t=(int(tmc_msg.location.lcn),int(tmc_msg.event.updateClass),tmc_msg.PI,tmc_msg.tmc_hash, tmc_msg.getTime(),int(tmc_msg.event.ecn),int(tmc_msg.is_single), int(tmc_msg.tmc_DP),int(tmc_msg.tmc_D),int(tmc_msg.tmc_dir),int(tmc_msg.tmc_extent), tmc_msg.location_text().decode("utf-8"),tmc_msg.events_string().decode("utf-8"),tmc_msg.info_str().decode("utf-8"),tmc_msg.multi_str().decode("utf-8")) self.db.execute("REPLACE INTO TMC (lcn,updateclass,hash,PI,time,ecn,isSingle,DP,div,dir,extent,locstr,eventstr,infostr,multistr) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",t) + self.dbLock.release(1) except Exception as e: if self.log or self.debug: print("error during db insert msg:%s"%tmc_msg.log_string())