diff --git a/NEWS b/NEWS index e240fca0..9eb2f53b 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,7 @@ Bugs corrected: * KeyError: 'memory_info' on stats sum #1188 * Electron/Atom processes displayed wrong in process list #1192 * Another encoding issue... With both Python 2 and Python 3 #1197 + * Glances do not exit when eating 'q' #1207 Backward-incompatible changes: diff --git a/glances/__init__.py b/glances/__init__.py index 973bd83b..a69a76f9 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -77,7 +77,7 @@ def end(): # ...after starting the server mode (issue #1175) pass - logger.info("Glances stopped with CTRL-C") + logger.info("Glances stopped (keypressed: CTRL-C)") # The end... sys.exit(0) @@ -118,6 +118,9 @@ def main(): Select the mode (standalone, client or server) Run it... """ + # Catch the CTRL-C signal + signal.signal(signal.SIGINT, __signal_handler) + # Log Glances and PSutil version logger.info('Start Glances {}'.format(__version__)) logger.info('{} {} and PSutil {} detected'.format( @@ -133,8 +136,5 @@ def main(): config = core.get_config() args = core.get_args() - # Catch the CTRL-C signal - signal.signal(signal.SIGINT, __signal_handler) - # Glances can be ran in standalone, client or server mode start(config=config, args=args) diff --git a/glances/main.py b/glances/main.py index f814aac5..e3334f8a 100644 --- a/glances/main.py +++ b/glances/main.py @@ -418,11 +418,11 @@ Examples of use: return self.mode def __get_username(self, description=''): - """Read an username from the command line. - """ + """Read an username from the command line.""" return input(description) - def __get_password(self, description='', confirm=False, clear=False, username='glances'): + def __get_password(self, description='', + confirm=False, clear=False, username='glances'): """Read a password from the command line. - if confirm = True, with confirmation diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index f4615775..006ffab4 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -341,9 +341,7 @@ class _GlancesCurses(object): if return_to_browser: logger.info("Stop Glances client and return to the browser") else: - self.end() - logger.info("Stop Glances") - sys.exit(0) + logger.info("Stop Glances (keypressed: {})".format(self.pressedkey)) elif self.pressedkey == ord('\n'): # 'ENTER' > Edit the process filter self.edit_filter = not self.edit_filter diff --git a/glances/standalone.py b/glances/standalone.py index 354e8217..2db3a6d5 100644 --- a/glances/standalone.py +++ b/glances/standalone.py @@ -100,7 +100,10 @@ class GlancesStandalone(object): ', '.join(sorted(self.stats.getExportsList(enable=False))))) def __serve_forever(self): - """Main loop for the CLI.""" + """Main loop for the CLI. + + return True if we should continue (no exit key has been pressed) + """ # Start a counter used to compute the time needed for # update and export the stats counter = Counter() @@ -117,13 +120,23 @@ class GlancesStandalone(object): # Display stats # and wait refresh_time - counter if not self.quiet: - self.screen.update(self.stats, - duration=self.refresh_time - counter.get()) + # The update function return True if an exit key 'q' or 'ESC' + # has been pressed. + ret = not self.screen.update(self.stats, + duration=self.refresh_time - counter.get()) + else: + # Nothing is displayed + # Break should be done via a signal (CTRL-C) + ret = True + + return ret def serve_forever(self): """Wrapper to the serve_forever function.""" - while True: - self.__serve_forever() + loop = True + while loop: + loop = self.__serve_forever() + self.end() def end(self): """End of the standalone CLI."""