From 3f851320391f2b14206c8f5112f270176c51a089 Mon Sep 17 00:00:00 2001 From: Chris Larson Date: Thu, 16 Dec 2010 08:38:57 -0700 Subject: [PATCH] Forcibly shut down the server if the UI is terminated Signed-off-by: Chris Larson --- bin/bitbake | 26 ++++++++++++++++---------- lib/bb/server/process.py | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/bin/bitbake b/bin/bitbake index 2cf131db8ab..fcf8ca56ca2 100755 --- a/bin/bitbake +++ b/bin/bitbake @@ -189,20 +189,26 @@ Default BBFILES are the .bb files in the current directory.""") server = ProcessServer(server_channel, event_queue, configuration) server.start() - try: - return ui_main(ServerCommunicator(ui_channel), event_queue) - finally: - # the server is stopping, so don't let the user do crazy things with - # extra Ctrl-C invocations. If the server does hang, however, the user - # won't be able to kill us. - # - # @todo come up with better mechanism - may need to catch KeyboardInterrupt - # here and do a server.terminate() + def shutdown(force=False): signal.signal(signal.SIGINT, signal.SIG_IGN) server.stop() - server.join() + if force: + server.join(0.5) + if server.is_alive(): + server.terminate() + server.join() + else: + server.join() ui_channel.close() event_queue.close() + if force: + sys.exit(1) + + signal.signal(signal.SIGTERM, lambda i, s: shutdown(force=True)) + try: + return ui_main(ServerCommunicator(ui_channel), event_queue) + finally: + shutdown() return 1 diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py index 77ef6adb5bd..c3aaa7fb9d4 100644 --- a/lib/bb/server/process.py +++ b/lib/bb/server/process.py @@ -108,7 +108,7 @@ class ProcessServer(Process): self.runCommand(command) self.idle_commands(.1) - except Exception, exc: + except Exception: logger.exception('Running command %s', command) self.event_queue.cancel_join_thread() -- 2.47.3