diff --git a/client/djrandom_client/client.py b/client/djrandom_client/client.py index 4686e52a03c1439f24e588b9f41d146b0110dc71..79d115305f4fbd1fa4d7c0e8827ceda11a1fb40d 100644 --- a/client/djrandom_client/client.py +++ b/client/djrandom_client/client.py @@ -61,7 +61,6 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit, enable_watcher upl = upload.Uploader(server_url.rstrip('/'), api_key) upl.setDaemon(True) - upl.start() # Start the full filesystem scan in the background. if enable_watcher: @@ -70,7 +69,6 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit, enable_watcher scan_delay = 9600 scan = FullScan(music_dir, upl.queue, scan_delay, run_once) scan.setDaemon(True) - scan.start() if not run_once: # Run at a lower priority. @@ -94,7 +92,16 @@ 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.join() + upl.start() + scan.start() + + # It turns out that, even if we set up signal handlers in this + # same main thread, they won't be executed if we're blocking on + # a mutex (such as 'upl.join()' for example)... so we do this + # silly idle loop in the main thread just to ensure that we + # catch SIGTERM and SIGINT. + while True: + time.sleep(3600) def main(): diff --git a/client/djrandom_client/upload.py b/client/djrandom_client/upload.py index 412046e34b8a89966883092250b66dd7fcd9afb4..7c657478f4d2fff7f17bd635e57f690fd147e724 100644 --- a/client/djrandom_client/upload.py +++ b/client/djrandom_client/upload.py @@ -135,6 +135,6 @@ class Uploader(threading.Thread): db.close() def stop(self): - # This runs in a different thread. + # This runs in a different thread. We can simply exit. pass