From 5d8a728d89ef4c84d10785b5ac5bf32cc1e3ede7 Mon Sep 17 00:00:00 2001 From: Filip Valder Date: Fri, 9 Dec 2016 12:35:44 +0100 Subject: [PATCH] fix #211: stay attached to the main thread to keep control (foreground mode) --- module_build_service/scheduler/main.py | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/module_build_service/scheduler/main.py b/module_build_service/scheduler/main.py index a2447806..d42dbc11 100644 --- a/module_build_service/scheduler/main.py +++ b/module_build_service/scheduler/main.py @@ -317,21 +317,22 @@ def main(initial_msgs=[], return_after_build=False): for msg in initial_msgs: outgoing_work_queue_put(msg) + # This ingest thread puts work on the queue + messaging_thread = MessageIngest(_work_queue, return_after_build) + # This poller does other work, but also sometimes puts work in queue. + polling_thread = Poller(_work_queue) + # This worker takes work off the queue and handles it. + worker_thread = MessageWorker(_work_queue, return_after_build) + + messaging_thread.start() + polling_thread.start() + worker_thread.start() + try: - # This ingest thread puts work on the queue - messaging_thread = MessageIngest(_work_queue, return_after_build) - # This poller does other work, but also sometimes puts work in queue. - polling_thread = Poller(_work_queue) - # This worker takes work off the queue and handles it. - worker_thread = MessageWorker(_work_queue, return_after_build) - - messaging_thread.start() - polling_thread.start() - worker_thread.start() - - worker_thread.join() - polling_thread.stop = True - + while worker_thread.is_alive(): + time.sleep(3) except KeyboardInterrupt: # FIXME: Make this less brutal os._exit(0) + finally: + polling_thread.stop = True