From efb4e943325f61426c9c6d88960f7218bb3cbf1c Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Wed, 28 Sep 2011 10:42:10 +0100 Subject: [PATCH] ensure that all sqlite objects stay in the same thread --- client/djrandom_client/upload.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/djrandom_client/upload.py b/client/djrandom_client/upload.py index f52bedd..412046e 100644 --- a/client/djrandom_client/upload.py +++ b/client/djrandom_client/upload.py @@ -65,7 +65,7 @@ class Uploader(threading.Thread): self.api_key = api_key self.server_url = server_url self.queue = Queue.Queue(100) - self.db = FileDatabase(db) + self.db_path = db self.opener = urllib2.build_opener(throttle.ThrottledHTTPHandler) user_agent = 'djrandom_client/%s (%s %s Python/%s)' % ( @@ -112,18 +112,19 @@ class Uploader(threading.Thread): log.info('successfully uploaded %s (%s)' % (path, sha1)) def run(self): + db = FileDatabase(self.db_path) try: while True: stats.data.set('uploading', None) path = self.queue.get() if path is None: break - if self.db.has(path): + if db.has(path): continue stats.data.set('uploading', path) try: self.upload(path) - self.db.add(path) + db.add(path) except Exception, e: log.error('error uploading %s: %s' % (path, str(e))) stats.data.incr('errors') @@ -131,9 +132,9 @@ class Uploader(threading.Thread): stats.data.set('last_error_timestamp', '%i' % time.time()) finally: log.debug('uploader thread exiting') - self.db.close() + db.close() def stop(self): # This runs in a different thread. - self.db.close() + pass -- GitLab