From 336dac1eabced3ec65557ce4ef95efbadb1017a8 Mon Sep 17 00:00:00 2001 From: csrichter Date: Thu, 18 May 2017 15:59:35 +0200 Subject: [PATCH] more locks (still doesnt work) --- python/tmc_parser.py | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/python/tmc_parser.py b/python/tmc_parser.py index 36ade2f..503723f 100644 --- a/python/tmc_parser.py +++ b/python/tmc_parser.py @@ -99,26 +99,26 @@ class tmc_parser(gr.sync_block): self.save_data() print("closing tmc display") def save_data(self): - #if self.debug: - # print("saving data") + print_dbg('saving data..', end="") + self.dataLock.acquire(1) if self.writeDB: self.dbLock.acquire(1) self.db.commit() self.dbLock.release(1) f=open(self.workdir+'google_maps_markers.js', 'w') - self.dataLock.acquire(1) + markerstring=self.tmc_messages.getMarkerString() self.dataLock.release(1) markerstring+='\n console.log("loaded "+markers.length+" markers")' markerstring+='\n document.getElementById("errorid").innerHTML = "loaded "+markers.length+" markers";' f.write(markerstring) f.close() - #if self.debug: - # print("saved") + print_dbg('saved') def print_tmc_msg(self,tmc_msg): - print_dbg('printing msg', end="") + print_dbg('parser:print', end="") if self.writeDB and tmc_msg.event.is_cancellation == False: try: + self.dataLock.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), @@ -127,15 +127,18 @@ class tmc_parser(gr.sync_block): self.dbLock.acquire(1) 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) + self.dataLock.release(1) print_dbg('.', end="") except Exception as e: if self.log or self.debug: print("error during db insert msg:%s"%tmc_msg.log_string()) print(e) pass - print_dbg("db done") + print_dbg("db-done") + #self.dataLock.acquire(1) self.qtwidget.print_tmc_msg(tmc_msg) - print_dbg("done") + #self.dataLock.release(1) + print_dbg("parser:done") #if self.debug: #print("new tmc message %s"%tmc_msg) @@ -174,8 +177,8 @@ class tmc_parser(gr.sync_block): tmc_msg=tmc_message(PI,psn,ltn,tmc_x,tmc_y,tmc_z,datetime_received,self) self.dataLock.acquire(1) self.tmc_messages.add(tmc_msg) - self.print_tmc_msg(tmc_msg) self.dataLock.release(1) + self.print_tmc_msg(tmc_msg) elif tmc_F==0 and Y15==1:#1st group of multigroup ci=int(tmc_x&0x7) tmc_msg=tmc_message(PI,psn,ltn,tmc_x,tmc_y,tmc_z,datetime_received,self) @@ -189,14 +192,18 @@ class tmc_parser(gr.sync_block): ci=int(tmc_x&0x7) if self.unfinished_messages[PI].has_key(ci): tmc_msg=self.unfinished_messages[PI][ci]["msg"] + self.dataLock.acquire(1) tmc_msg.add_group(tmc_y,tmc_z) + self.dataLock.release(1) age=time.time()-self.unfinished_messages[PI][ci]["time"] - t=(time.time(),PI,age,ci,tmc_msg.is_complete) + #t=(time.time(),PI,age,ci,tmc_msg.is_complete) #print("%f: continuing message PI:%s,age:%f,ci:%i complete:%i"%t) self.unfinished_messages[PI]["time"]=time.time() if tmc_msg.is_complete: self.print_tmc_msg(tmc_msg)#print message + self.dataLock.acquire(1)#wait for print before delete del self.unfinished_messages[PI][tmc_msg.ci]#delete finished message + self.dataLock.release(1) else: #if not ci==0: #print("ci %i not found, discarding"%ci) @@ -277,12 +284,13 @@ class tmc_parser(gr.sync_block): pass return return_string def print_dbg(message,end="\n"): - dbg=False + dbg=True if dbg: print(message,end=end) class tmc_parser_Widget(QtGui.QWidget): def print_tmc_msg(self,tmc_msg): + self.parser.dataLock.acquire(1) self.logMutex.acquire(1) print_dbg("print:got mutex,",end="") sb=self.logOutput.verticalScrollBar() @@ -307,30 +315,36 @@ class tmc_parser_Widget(QtGui.QWidget): sb.setValue(new_max) print_dbg("s",end="") self.logMutex.release(1) + self.parser.dataLock.release(1) print_dbg("\tdone") def filterChanged(self): + self.parser.dataLock.acquire(1) self.logMutex.acquire(1) - #code.interact(local=locals()) - print_dbg("filterChanged:got mutex,",end="") + print("filterChanged:got mutex,",end="") ef="" lf="" try: ef=unicode(self.event_filter.text().toUtf8(), encoding="UTF-8").lower() lf=unicode(self.location_filter.text().toUtf8(), encoding="UTF-8").lower() except Exception as e: - print_dbg(e) - print_dbg("error getting filter strings") + print(e) + print("error getting filter strings") code.interact(local=locals()) - print_dbg("read filters,",end="") + print("read filters,",end="") self.logOutput.clear() - print_dbg("cleared,",end="") + print("cleared,",end="") filters=[{"type":"location", "str":lf},{"type":"event", "str":ef}] #print("getting logstring with filters:%s, showInvalid:%i"%(filters,self.showInvalid)) - self.logOutput.append(Qt.QString.fromUtf8(self.parser.tmc_messages.getLogString(self.showInvalid,filters))) - print_dbg("appended,",end="") + + logstr=self.parser.tmc_messages.getLogString(self.showInvalid,filters) + + print("got str,",end="") + self.logOutput.append(Qt.QString.fromUtf8(logstr)) self.logMutex.release(1) - print_dbg("done") + print("appended,",end="") + self.parser.dataLock.release(1) + print("done") def update_showInvalid(self): self.showInvalid=self.GUI_showInvalid.isChecked() def __init__(self, parser,maxheight):