Skip to content
Snippets Groups Projects
Commit efb4e943 authored by ale's avatar ale
Browse files

ensure that all sqlite objects stay in the same thread

parent 90e1a7e8
Branches
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment