Database doesn't need to be a thread; recorder code cleanup

This commit is contained in:
dave 2014-08-26 17:35:55 -07:00
parent 4ec778d0a5
commit 68d3e84072
2 changed files with 2 additions and 31 deletions

View File

@ -1,14 +1,13 @@
#!/usr/bin/env python3
import sqlite3
import threading
class database(threading.Thread):
class database:
def __init__(self):
threading.Thread.__init__(self)
self.db = None
# TODO: If db.sqlite doesn't exist, create one with the following demo data
#self.createDatabase()
self.start()
self.openDB()
def createDatabase(self):
queries = [
@ -18,9 +17,6 @@ class database(threading.Thread):
"""INSERT INTO "times" ("id","streamid","su","m","t","w","r","f","sa","starthour","startmin","endhour","endmin") VALUES (NULL,'1','0','1','1','1','1','1','0','2','0','7','15')"""
]
def run(self):
self.db = self.openDB()
def openDB(self):
db = sqlite3.connect("db.sqlite", check_same_thread=False, cached_statements=0, isolation_level=None)
db.row_factory = self.dict_factory

View File

@ -17,24 +17,6 @@ class recordTick:
# list of downloader threads
self.threads = {}
def run(self):
time.sleep(3)
## TESTING CODE
#now=datetime.datetime.now()
#self.db.execute('UPDATE "times" SET "starthour"=?, "startmin"=?, "endhour"=?, "endmin"=? WHERE "streamid"=? ;', (now.hour, now.minute, now.hour, now.minute+1, 1))
#self.tick()
## END TESTING CODE
#self.scheduleTick()
## TESTING CODE
while True:
time.sleep(self.timeToNextMinute())
self.tick()
print("Ticked")
def tick(self):
now=datetime.datetime.now()
#print("Tick start: %s" % now)
@ -80,13 +62,6 @@ class recordTick:
def getSelf(self):
return self
def scheduleTick(self):
# schedule tick in the next minute
self.timer.enter(self.timeToNextMinute(), 1, self.tick)
self.timer.run()
# Schedule the next tick
Thread(target=self.scheduleTick).start()
def timeToNextMinute(self):
# calculate time to the milliscond until the next minute rolls over
# Find the next minute