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

try to run the uploader in a separate thread

parent 12ff77e3
Branches
No related tags found
No related merge requests found
......@@ -60,6 +60,8 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit, enable_watcher
enable_watcher = False
upl = upload.Uploader(server_url.rstrip('/'), api_key)
upl.setDaemon(True)
upl.start()
# Start the full filesystem scan in the background.
if enable_watcher:
......@@ -92,7 +94,7 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit, enable_watcher
signal.signal(signal.SIGINT, _cleanup)
signal.signal(signal.SIGTERM, _cleanup)
upl.run()
upl.join()
def main():
......
......@@ -58,9 +58,10 @@ class FileDatabase(object):
self.conn.commit()
class Uploader(object):
class Uploader(threading.Thread):
def __init__(self, server_url, api_key, db=None):
threading.Thread.__init__(self)
self.api_key = api_key
self.server_url = server_url
self.queue = Queue.Queue(100)
......@@ -133,8 +134,6 @@ class Uploader(object):
self.db.close()
def stop(self):
# 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.
# This runs in a different thread.
self.db.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment