From 6f3a537dda7ea84379fc11c1ec42cfdfeaf68bd4 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sun, 9 Mar 2014 10:04:41 -0700 Subject: bitbake: server/process: Deal more gracefully with SIGTERM Currently a SIGTERM to the UI process causes the UI simply to lock up. By setting an exit flag, the waitEvent can raise a SIGINT, allowing the UI to break out the event loop and exit. Currently this is results in a traceback but that is more desirable than a hanging process. (Bitbake rev: 0d12041eceeae6bba2034b04913bb13abd67bd15) Signed-off-by: Richard Purdie --- bitbake/lib/bb/server/process.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'bitbake/lib/bb/server') diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 6db6a2326d..f4cb32c8aa 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py @@ -157,6 +157,10 @@ class BitBakeProcessServerConnection(BitBakeBaseServerConnection): self.connection = ServerCommunicator(self.ui_channel, self.procserver.event_handle) self.events = self.event_queue + def sigterm_terminate(self): + bb.error("UI received SIGTERM") + self.terminate() + def terminate(self): def flushevents(): while True: @@ -176,10 +180,20 @@ class BitBakeProcessServerConnection(BitBakeBaseServerConnection): self.ui_channel.close() self.event_queue.close() + self.event_queue.setexit() # Wrap Queue to provide API which isn't server implementation specific class ProcessEventQueue(multiprocessing.queues.Queue): + def __init__(self, maxsize): + multiprocessing.queues.Queue.__init__(self, maxsize) + self.exit = False + + def setexit(self): + self.exit = True + def waitEvent(self, timeout): + if self.exit: + raise KeyboardInterrupt() try: return self.get(True, timeout) except Empty: @@ -214,5 +228,5 @@ class BitBakeServer(BitBakeBaseServer): if error: logger.error("Unable to set the cooker to the correct featureset: %s" % error) raise BaseException(error) - signal.signal(signal.SIGTERM, lambda i, s: self.connection.terminate()) + signal.signal(signal.SIGTERM, lambda i, s: self.connection.sigterm_terminate()) return self.connection -- cgit v1.2.3-54-g00ecf