From 2f4b2ccf48648e3847241e5e43e9641fa45646fd Mon Sep 17 00:00:00 2001 From: Steve Penrod Date: Mon, 2 Dec 2019 17:54:44 -0600 Subject: [PATCH] Remove signal.SIGINT handler from simple CLI At some point during refactoring the ability to hit Ctrl+C to exit the basic CLI was lost. The signal.SIGINT handler is needed by the graphical GUI, but it interfered with the use of sys.stdin.readline() in the simple CLI. Rearrange the installation of the handler for only the GUI. To test, run: mycroft-cli-client --simple Then hit Ctrl+C. Before this change nothing happens (you just see the "^C" printed out). After the change it exits as expected. --- mycroft/client/text/__main__.py | 6 +++++- mycroft/client/text/text_client.py | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mycroft/client/text/__main__.py b/mycroft/client/text/__main__.py index 4dd7bc4f28..6cb014870a 100644 --- a/mycroft/client/text/__main__.py +++ b/mycroft/client/text/__main__.py @@ -13,13 +13,15 @@ # limitations under the License. # import sys +import signal import io import os.path import curses from mycroft.util import get_ipc_directory from .text_client import ( load_settings, save_settings, simple_cli, gui_main, - start_log_monitor, start_mic_monitor, connect_to_mycroft + start_log_monitor, start_mic_monitor, connect_to_mycroft, + ctrl_c_handler ) from mycroft.configuration import Configuration @@ -57,6 +59,8 @@ def main(): sys.stderr = sys.__stderr__ simple_cli() else: + # Special signal handler allows a clean shutdown of the GUI + signal.signal(signal.SIGINT, ctrl_c_handler) load_settings() curses.wrapper(gui_main) curses.endwin() diff --git a/mycroft/client/text/text_client.py b/mycroft/client/text/text_client.py index 51cdb8e1c1..859cd22ccd 100644 --- a/mycroft/client/text/text_client.py +++ b/mycroft/client/text/text_client.py @@ -14,7 +14,6 @@ # import sys import io -import signal from math import ceil from .gui_server import start_qml_gui @@ -121,9 +120,6 @@ def ctrl_c_pressed(): return False -signal.signal(signal.SIGINT, ctrl_c_handler) - - ############################################################################## # Helper functions