From 8b1a47b2954cb73e9a5463f9cd7b7a5d3201d631 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 1 Sep 2003 08:38:25 +0000 Subject: [PATCH] Attempt to solve the atexit-closed-database problem. --- plugins/FunDB.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/FunDB.py b/plugins/FunDB.py index a20618976..c276c1226 100755 --- a/plugins/FunDB.py +++ b/plugins/FunDB.py @@ -112,6 +112,15 @@ def makeDb(dbfilename, replace=False): db.commit() 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): word = word.strip().lower() L = list(word) @@ -137,16 +146,9 @@ class FunDB(callbacks.Privmsg): callbacks.Privmsg.__init__(self) self.db = makeDb(dbFilename) cursor = self.db.cursor() - started = int(world.startedAt) cursor.execute("""INSERT INTO uptime VALUES (%s, NULL)""", started) self.db.commit() - def f(): - 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) + atexit.register(uptimeEnder(int(world.startedAt))) def die(self): self.db.commit()