Browse Source

added db mutex

dev
Clemens Richter 9 years ago
parent
commit
0da545d9c7
  1. 7
      python/tmc_parser.py

7
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_name=workdir+'RDS_data'+datetime.now().strftime("%Y%m%d_%H%M%S")+'_TMC.db'
db=sqlite3.connect(db_name, check_same_thread=False) db=sqlite3.connect(db_name, check_same_thread=False)
self.db=db self.db=db
self.dbLock=QtCore.QSemaphore(1)
#create tables #create tables
try: try:
@ -97,8 +98,12 @@ class tmc_parser(gr.sync_block):
self.save_data() self.save_data()
print("closing tmc display") print("closing tmc display")
def save_data(self): def save_data(self):
#if self.debug:
# print("saving data")
if self.writeDB: if self.writeDB:
self.dbLock.acquire(1)
self.db.commit() self.db.commit()
self.dbLock.release(1)
f=open(self.workdir+'google_maps_markers.js', 'w') f=open(self.workdir+'google_maps_markers.js', 'w')
markerstring=self.tmc_messages.getMarkerString() markerstring=self.tmc_messages.getMarkerString()
markerstring+='\n console.log("loaded "+markers.length+" markers")' 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): def print_tmc_msg(self,tmc_msg):
if self.writeDB and tmc_msg.event.is_cancellation == False: if self.writeDB and tmc_msg.event.is_cancellation == False:
try: try:
self.dbLock.acquire(1)
t=(int(tmc_msg.location.lcn),int(tmc_msg.event.updateClass),tmc_msg.PI,tmc_msg.tmc_hash, 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), 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), 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")) 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.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: except Exception as e:
if self.log or self.debug: if self.log or self.debug:
print("error during db insert msg:%s"%tmc_msg.log_string()) print("error during db insert msg:%s"%tmc_msg.log_string())

Loading…
Cancel
Save