From 90e1a7e83c18a2699f29dd08f8802d61eee606d2 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Wed, 28 Sep 2011 10:39:08 +0100
Subject: [PATCH] try to run the uploader in a separate thread

---
 client/djrandom_client/client.py | 4 +++-
 client/djrandom_client/upload.py | 7 +++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/client/djrandom_client/client.py b/client/djrandom_client/client.py
index 0baee71..4686e52 100644
--- a/client/djrandom_client/client.py
+++ b/client/djrandom_client/client.py
@@ -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():
diff --git a/client/djrandom_client/upload.py b/client/djrandom_client/upload.py
index 38c6628..f52bedd 100644
--- a/client/djrandom_client/upload.py
+++ b/client/djrandom_client/upload.py
@@ -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()
 
-- 
GitLab