Attempt to solve the atexit-closed-database problem.

This commit is contained in:
Jeremy Fincher 2003-09-01 08:38:25 +00:00
parent 35aff3f642
commit 8b1a47b295

View File

@ -112,6 +112,15 @@ def makeDb(dbfilename, replace=False):
db.commit() db.commit()
return db return db
def uptimeEnder(started):
def f():
db = makeDb(dbFilename)
cursor = db.cursor()
cursor.execute("""UPDATE uptime SET ended=%s WHERE started=%s""",
int(time.time()), started)
db.commit()
return f
def addWord(db, word, commit=False): def addWord(db, word, commit=False):
word = word.strip().lower() word = word.strip().lower()
L = list(word) L = list(word)
@ -137,16 +146,9 @@ class FunDB(callbacks.Privmsg):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
self.db = makeDb(dbFilename) self.db = makeDb(dbFilename)
cursor = self.db.cursor() cursor = self.db.cursor()
started = int(world.startedAt)
cursor.execute("""INSERT INTO uptime VALUES (%s, NULL)""", started) cursor.execute("""INSERT INTO uptime VALUES (%s, NULL)""", started)
self.db.commit() self.db.commit()
def f(): atexit.register(uptimeEnder(int(world.startedAt)))
db = makeDb(dbFilename)
cursor = db.cursor()
cursor.execute("""UPDATE uptime SET ended=%s WHERE started=%s""",
int(time.time()), started)
db.commit()
atexit.register(f)
def die(self): def die(self):
self.db.commit() self.db.commit()