From 11c80f1d4985b21b5800b981428f7bf88fa9778b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 7 Oct 2010 13:11:07 +0200 Subject: recycle sqlite connection --- module/FileDatabase.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'module/FileDatabase.py') diff --git a/module/FileDatabase.py b/module/FileDatabase.py index 6e6537f38..4bcb63764 100644 --- a/module/FileDatabase.py +++ b/module/FileDatabase.py @@ -562,15 +562,17 @@ class FileDatabaseBackend(Thread): self.c = self.conn.cursor() #self.c.execute("PRAGMA synchronous = OFF") self._createTables() - self.c.close() + + self.used = 0 while True: try: f, args, async = self.jobs.get() + self.used += 1 if f == "quit": return True - self.c = self.conn.cursor() + if self.used > 300: #recycle connection + self.recycleConnection() res = f(*args) - self.c.close() if not async: self.res.put(res) except Exception, e: #@TODO log etc @@ -582,6 +584,17 @@ class FileDatabaseBackend(Thread): self.syncSave() self.jobs.put(("quit", "", 0)) + def recycleConnection(self): + self.manager.core.log.debug("Recycle sqlite connection") + self.conn.commit() + self.c.close() + self.conn.close() + del self.c + del self.conn + self.conn = sqlite3.connect("files.db") + self.c = self.conn.cursor() + self.used = 0 + def _checkVersion(self): """ check db version and delete it if needed""" if not exists("files.version"): -- cgit v1.2.3