Use a common lock for the KMLgen and SQL threads to keep them from stepping on each other when reading the SQLite db

This commit is contained in:
Nick Foster
2012-10-09 09:26:16 -07:00
parent d86e568ac2
commit 67b58d7204
4 changed files with 47 additions and 44 deletions

View File

@@ -252,11 +252,12 @@ class mainwindow(QtGui.QMainWindow):
self.outputs = [self.datamodelout.output]
self.updates = []
self.lock = threading.Lock() #grab a lock to ensure sql and kml don't step on each other
#output options to populate outputs, updates
if self.ui.check_kml.checkState():
#we spawn a thread to run every 30 seconds (or whatever) to generate KML
self.kmlgen = air_modes.output_kml(self.ui.line_kmlfilename.text(), self.dbname, my_position) #create a KML generating thread
self.kmlgen = air_modes.output_kml(self.ui.line_kmlfilename.text(), self.dbname, my_position, self.lock) #create a KML generating thread
if self.ui.check_sbs1.checkState():
sbs1port = int(self.ui.line_sbs1port.text())
@@ -281,7 +282,7 @@ class mainwindow(QtGui.QMainWindow):
self.outputs.append(self.output_live_data)
#create SQL database for KML and dashboard displays
self.dbwriter = air_modes.output_sql(my_position, self.dbname)
self.dbwriter = air_modes.output_sql(my_position, self.dbname, self.lock)
self.outputs.append(self.dbwriter.output) #now the db will update itself
#output to update reports/sec widget

View File

@@ -194,8 +194,9 @@ if __name__ == '__main__':
if options.kml is not None:
#we spawn a thread to run every 30 seconds (or whatever) to generate KML
dbname = 'adsb.db'
sqldb = air_modes.output_sql(my_position, dbname) #input into the db
kmlgen = air_modes.output_kml(options.kml, dbname, my_position) #create a KML generating thread to read from the db
lock = threading.Lock()
sqldb = air_modes.output_sql(my_position, dbname, lock) #input into the db
kmlgen = air_modes.output_kml(options.kml, dbname, my_position, lock) #create a KML generating thread to read from the db
outputs.append(sqldb.output)
if options.sbs1 is True: