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

properly sync the database on exit

parent 1c29f168
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import optparse
import os
import platform
import signal
import sys
import threading
import time
from djrandom_client import daemonize
......@@ -72,6 +73,7 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit):
wtch.stop()
log.info('got signal %d, exiting...' % signum)
upl.stop()
sys.exit(0)
signal.signal(signal.SIGINT, _cleanup)
signal.signal(signal.SIGTERM, _cleanup)
......
......@@ -38,7 +38,7 @@ class Uploader(object):
def __init__(self, server_url, api_key, db=None):
self.api_key = api_key
self.server_url = server_url
self.queue = Queue.Queue(1000)
self.queue = Queue.Queue(100)
self.db = FileDatabase(db)
self.opener = urllib2.build_opener(throttle.ThrottledHTTPHandler)
socket.setdefaulttimeout(60)
......@@ -102,5 +102,8 @@ class Uploader(object):
self.db.close()
def stop(self):
self.queue.put(None)
# We can't put 'None' in the queue and exit cleanly because the
# signal handler might run in the same thread as the 'run()' method,
# causing a deadlock.
self.db.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment