summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-01-11 02:13:02 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-01-11 02:25:16 +0900
commit40a6a9554824ee18c95be4a545a7f20a9cb25f8d (patch)
treee5d72b6c9c0402f09b31e1f946b927e9ae6818f1
parent9a291305a8fc63958c1475af47aab5b76b858ec8 (diff)
downloadbuildstream-tristan/fix-cache-init.tar.gz
_artifactcache/ostreecache.py: Handle ^C and shutdown child task when initializing cachetristan/fix-cache-init
This fixes issue #141
-rw-r--r--buildstream/_artifactcache/ostreecache.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py
index 78796dc6c..2eff50a98 100644
--- a/buildstream/_artifactcache/ostreecache.py
+++ b/buildstream/_artifactcache/ostreecache.py
@@ -22,8 +22,9 @@ import multiprocessing
import os
import string
import tempfile
+import signal
-from .. import _ostree, utils
+from .. import _ostree, _signals, utils
from .._exceptions import ArtifactError
from ..element import _KeyStrength
from .._ostree import OSTreeError
@@ -308,18 +309,27 @@ class OSTreeCache(ArtifactCache):
try:
q.put((True, _ostree.list_remote_refs(self.repo, remote=remote)))
except OSTreeError as e:
- q.put((False, e))
+ q.put((False, str(e)))
q = multiprocessing.Queue()
p = multiprocessing.Process(target=child_action, args=(self.repo, remote, q))
- p.start()
- ret, res = q.get()
- p.join()
+
+ try:
+
+ # Keep SIGINT blocked in the child process
+ with _signals.blocked([signal.SIGINT], ignore=False):
+ p.start()
+
+ ret, res = q.get()
+ p.join()
+ except KeyboardInterrupt:
+ utils._kill_process_tree(p.pid)
+ raise
if ret:
self._remote_refs = res
else:
- raise ArtifactError("Failed to fetch remote refs") from res
+ raise ArtifactError("Failed to fetch remote refs: {}".format(res))
# push():
#