From e8e1ad70893496f8956559775391500149a1205d Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Sun, 2 Oct 2016 19:12:03 +0800 Subject: [PATCH] Handle the KeyboardInterrunpt properly for build.py script * set the push queue worker daemon * force exit when using twice Ctrl + c in build.py script. Change-Id: Ib3278ee9909f94a5129854c3c6fc9720a91a19f3 Closes-Bug: #1629654 --- kolla/image/build.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kolla/image/build.py b/kolla/image/build.py index eee5b036b2..d0d36a457a 100644 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -117,9 +117,21 @@ STATUS_ERRORS = (STATUS_CONNECTION_ERROR, STATUS_PUSH_ERROR, def join_many(threads): try: yield - finally: for t in threads: t.join() + except KeyboardInterrupt: + try: + LOG.info('Waiting for daemon threads exit. Push Ctrl + c again to' + ' force exit') + for t in threads: + if t.is_alive(): + LOG.debug('Waiting thread %s to exit', t.name) + # NOTE(Jeffrey4l): Python Bug: When join without timeout, + # KeyboardInterrupt is never sent. + t.join(0xffff) + LOG.debug('Thread %s exits', t.name) + except KeyboardInterrupt: + LOG.warning('Force exits') class DockerTask(task.Task): @@ -974,6 +986,7 @@ def run_build(): for x in six.moves.range(conf.push_threads): worker = WorkerThread(conf, push_queue) + worker.setDaemon(True) worker.start() workers.append(worker)