Browse Source

more locks (still doesnt work)

dev
Clemens Richter 9 years ago
parent
commit
336dac1eab
  1. 54
      python/tmc_parser.py

54
python/tmc_parser.py

@ -99,26 +99,26 @@ 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_dbg('saving data..', end="")
# print("saving data") self.dataLock.acquire(1)
if self.writeDB: if self.writeDB:
self.dbLock.acquire(1) self.dbLock.acquire(1)
self.db.commit() self.db.commit()
self.dbLock.release(1) self.dbLock.release(1)
f=open(self.workdir+'google_maps_markers.js', 'w') f=open(self.workdir+'google_maps_markers.js', 'w')
self.dataLock.acquire(1)
markerstring=self.tmc_messages.getMarkerString() markerstring=self.tmc_messages.getMarkerString()
self.dataLock.release(1) self.dataLock.release(1)
markerstring+='\n console.log("loaded "+markers.length+" markers")' markerstring+='\n console.log("loaded "+markers.length+" markers")'
markerstring+='\n document.getElementById("errorid").innerHTML = "loaded "+markers.length+" markers";' markerstring+='\n document.getElementById("errorid").innerHTML = "loaded "+markers.length+" markers";'
f.write(markerstring) f.write(markerstring)
f.close() f.close()
#if self.debug: print_dbg('saved')
# print("saved")
def print_tmc_msg(self,tmc_msg): 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: if self.writeDB and tmc_msg.event.is_cancellation == False:
try: try:
self.dataLock.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),
@ -127,15 +127,18 @@ class tmc_parser(gr.sync_block):
self.dbLock.acquire(1) 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.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.dbLock.release(1)
self.dataLock.release(1)
print_dbg('.', end="") print_dbg('.', end="")
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())
print(e) print(e)
pass pass
print_dbg("db done") print_dbg("db-done")
#self.dataLock.acquire(1)
self.qtwidget.print_tmc_msg(tmc_msg) self.qtwidget.print_tmc_msg(tmc_msg)
print_dbg("done") #self.dataLock.release(1)
print_dbg("parser:done")
#if self.debug: #if self.debug:
#print("new tmc message %s"%tmc_msg) #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) tmc_msg=tmc_message(PI,psn,ltn,tmc_x,tmc_y,tmc_z,datetime_received,self)
self.dataLock.acquire(1) self.dataLock.acquire(1)
self.tmc_messages.add(tmc_msg) self.tmc_messages.add(tmc_msg)
self.print_tmc_msg(tmc_msg)
self.dataLock.release(1) self.dataLock.release(1)
self.print_tmc_msg(tmc_msg)
elif tmc_F==0 and Y15==1:#1st group of multigroup elif tmc_F==0 and Y15==1:#1st group of multigroup
ci=int(tmc_x&0x7) ci=int(tmc_x&0x7)
tmc_msg=tmc_message(PI,psn,ltn,tmc_x,tmc_y,tmc_z,datetime_received,self) 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) ci=int(tmc_x&0x7)
if self.unfinished_messages[PI].has_key(ci): if self.unfinished_messages[PI].has_key(ci):
tmc_msg=self.unfinished_messages[PI][ci]["msg"] tmc_msg=self.unfinished_messages[PI][ci]["msg"]
self.dataLock.acquire(1)
tmc_msg.add_group(tmc_y,tmc_z) tmc_msg.add_group(tmc_y,tmc_z)
self.dataLock.release(1)
age=time.time()-self.unfinished_messages[PI][ci]["time"] 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) #print("%f: continuing message PI:%s,age:%f,ci:%i complete:%i"%t)
self.unfinished_messages[PI]["time"]=time.time() self.unfinished_messages[PI]["time"]=time.time()
if tmc_msg.is_complete: if tmc_msg.is_complete:
self.print_tmc_msg(tmc_msg)#print message 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 del self.unfinished_messages[PI][tmc_msg.ci]#delete finished message
self.dataLock.release(1)
else: else:
#if not ci==0: #if not ci==0:
#print("ci %i not found, discarding"%ci) #print("ci %i not found, discarding"%ci)
@ -277,12 +284,13 @@ class tmc_parser(gr.sync_block):
pass pass
return return_string return return_string
def print_dbg(message,end="\n"): def print_dbg(message,end="\n"):
dbg=False dbg=True
if dbg: if dbg:
print(message,end=end) print(message,end=end)
class tmc_parser_Widget(QtGui.QWidget): class tmc_parser_Widget(QtGui.QWidget):
def print_tmc_msg(self,tmc_msg): def print_tmc_msg(self,tmc_msg):
self.parser.dataLock.acquire(1)
self.logMutex.acquire(1) self.logMutex.acquire(1)
print_dbg("print:got mutex,",end="") print_dbg("print:got mutex,",end="")
sb=self.logOutput.verticalScrollBar() sb=self.logOutput.verticalScrollBar()
@ -307,30 +315,36 @@ class tmc_parser_Widget(QtGui.QWidget):
sb.setValue(new_max) sb.setValue(new_max)
print_dbg("s",end="") print_dbg("s",end="")
self.logMutex.release(1) self.logMutex.release(1)
self.parser.dataLock.release(1)
print_dbg("\tdone") print_dbg("\tdone")
def filterChanged(self): def filterChanged(self):
self.parser.dataLock.acquire(1)
self.logMutex.acquire(1) self.logMutex.acquire(1)
#code.interact(local=locals()) print("filterChanged:got mutex,",end="")
print_dbg("filterChanged:got mutex,",end="")
ef="" ef=""
lf="" lf=""
try: try:
ef=unicode(self.event_filter.text().toUtf8(), encoding="UTF-8").lower() ef=unicode(self.event_filter.text().toUtf8(), encoding="UTF-8").lower()
lf=unicode(self.location_filter.text().toUtf8(), encoding="UTF-8").lower() lf=unicode(self.location_filter.text().toUtf8(), encoding="UTF-8").lower()
except Exception as e: except Exception as e:
print_dbg(e) print(e)
print_dbg("error getting filter strings") print("error getting filter strings")
code.interact(local=locals()) code.interact(local=locals())
print_dbg("read filters,",end="") print("read filters,",end="")
self.logOutput.clear() self.logOutput.clear()
print_dbg("cleared,",end="") print("cleared,",end="")
filters=[{"type":"location", "str":lf},{"type":"event", "str":ef}] filters=[{"type":"location", "str":lf},{"type":"event", "str":ef}]
#print("getting logstring with filters:%s, showInvalid:%i"%(filters,self.showInvalid)) #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) self.logMutex.release(1)
print_dbg("done") print("appended,",end="")
self.parser.dataLock.release(1)
print("done")
def update_showInvalid(self): def update_showInvalid(self):
self.showInvalid=self.GUI_showInvalid.isChecked() self.showInvalid=self.GUI_showInvalid.isChecked()
def __init__(self, parser,maxheight): def __init__(self, parser,maxheight):

Loading…
Cancel
Save