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

run an idle loop in the main thread to correctly catch signals

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