diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-11 01:30:59 +0900 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2018-01-11 18:18:14 +0000 |
commit | 20d653de3c46aa66b70116de68b78487225b2f23 (patch) | |
tree | c59149ad131c8a7221070b17bd5f9b7aac498704 | |
parent | a59ebbf084a8c3dd38cfdee4587a525dc01154c7 (diff) | |
download | buildstream-20d653de3c46aa66b70116de68b78487225b2f23.tar.gz |
_artifactcache/ostreecache.py: Handle ^C and shutdown child task when initializing cache
This fixes issue #141
-rw-r--r-- | buildstream/_artifactcache/ostreecache.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py index 9fe72a63e..7c4e367e9 100644 --- a/buildstream/_artifactcache/ostreecache.py +++ b/buildstream/_artifactcache/ostreecache.py @@ -20,10 +20,11 @@ import multiprocessing import os +import signal import string import tempfile -from .. import _ostree, utils +from .. import _ostree, _signals, utils from .._exceptions import ArtifactError from ..element import _KeyStrength from .._ostree import OSTreeError @@ -384,9 +385,18 @@ class OSTreeCache(ArtifactCache): q = multiprocessing.Queue() for remote in self.remote_specs: p = multiprocessing.Process(target=child_action, args=(remote.url, q)) - p.start() - exception, push_url, pull_url, remote_refs = q.get() - p.join() + + try: + + # Keep SIGINT blocked in the child process + with _signals.blocked([signal.SIGINT], ignore=False): + p.start() + + exception, push_url, pull_url, remote_refs = q.get() + p.join() + except KeyboardInterrupt: + utils._kill_process_tree(p.pid) + raise if exception and on_failure: on_failure(remote.url, exception) |