From e2126652a3a1e08724a54091793bb29a79d31014 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Wed, 5 Sep 2012 10:35:06 +0200 Subject: [PATCH] Make "repo sync -j" stop properly on Ctrl-C. The threaded 'repo sync' implementation would very often freeze the process when interrupted by the user with Ctrl-C. The only solution being to kill -9 the process explicitly from another terminal. The reason for this is best explained here: http://snakesthatbite.blogspot.fr/2010/09/cpython-threading-interrupting.html This patch makes all helper sync threads 'daemon', which allows the process to terminate immediately on Ctrl-C. Note that this will forcefully kill all threads in case of interruption; this is generally a bad thing, but: 1/ This is equivalent to calling kill -9 in another terminal, which is the _only_ thing that can currently stop the process. 2/ There doesn't seem to be a way to tell the worker threads to gently stop when they are in a blocking operation anyway (even in the non-threaded case). + Do the same for "repo status -j". Change-Id: Ieaf45b0eacee36f35427f8edafd87415c2aa7be4 --- subcmds/status.py | 1 + subcmds/sync.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/subcmds/status.py b/subcmds/status.py index 69e2dbfc..75d68ebc 100644 --- a/subcmds/status.py +++ b/subcmds/status.py @@ -122,6 +122,7 @@ the following meanings: t = _threading.Thread(target=self._StatusHelper, args=(project, counter, sem, output)) threads_and_output.append((t, output)) + t.daemon = True t.start() for (t, output) in threads_and_output: t.join() diff --git a/subcmds/sync.py b/subcmds/sync.py index bfe146b6..595a35aa 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -261,6 +261,8 @@ later is required to fix a server side protocol bug. pm, sem, err_event)) + # Ensure that Ctrl-C will not freeze the repo process. + t.daemon = True threads.add(t) t.start()