diff --git a/.gitignore b/.gitignore index 076ec7c2..a36be1de 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ _build # web ui node_modules/ bower_components/ + +# visual stdio code +.vscode/ \ No newline at end of file diff --git a/glances/client_browser.py b/glances/client_browser.py index 6a7977cb..53e41e51 100644 --- a/glances/client_browser.py +++ b/glances/client_browser.py @@ -219,12 +219,16 @@ class GlancesClientBrowser(object): # It's done by the GlancesAutoDiscoverListener class (autodiscover.py) # Or define staticaly in the configuration file (module static_list.py) # For each server in the list, grab elementary stats (CPU, LOAD, MEM, OS...) - - while True: + thread_list = {} + while self.screen.is_end == False: logger.debug("Iter through the following server list: {}".format(self.get_servers_list())) for v in self.get_servers_list(): - thread = threading.Thread(target=self.__update_stats, args=[v]) - thread.start() + key = v["key"] + thread = thread_list.get(key, None) + if thread is None or thread.is_alive() == False: + thread = threading.Thread(target=self.__update_stats, args=[v]) + thread_list[key] = thread + thread.start() # Update the screen (list or Glances client) if self.screen.active_server is None: @@ -234,6 +238,10 @@ class GlancesClientBrowser(object): # Display the active server self.__display_server(self.get_servers_list()[self.screen.active_server]) + # exit key pressed + for thread in thread_list.values(): + thread.join() + def serve_forever(self): """Wrapper to the serve_forever function. diff --git a/glances/outputs/glances_curses_browser.py b/glances/outputs/glances_curses_browser.py index 60665bbb..8ed35e18 100644 --- a/glances/outputs/glances_curses_browser.py +++ b/glances/outputs/glances_curses_browser.py @@ -61,6 +61,8 @@ class GlancesCursesBrowser(_GlancesCurses): self._page_max = 0 self._page_max_lines = 0 + self.is_end = False + @property def active_server(self): """Return the active server or None if it's the browser list.""" @@ -124,6 +126,8 @@ class GlancesCursesBrowser(_GlancesCurses): """Set next page.""" if self._current_page + 1 < self._page_max: self._current_page += 1 + else: + self._current_page = 0 self.cursor_position = 0 def __catch_key(self, stats): @@ -138,7 +142,8 @@ class GlancesCursesBrowser(_GlancesCurses): # 'ESC'|'q' > Quit self.end() logger.info("Stop Glances client browser") - sys.exit(0) + # sys.exit(0) + self.is_end = True elif self.pressedkey == 10: # 'ENTER' > Run Glances on the selected server self.active_server = self._current_page * self._page_max_lines + self.cursor_position @@ -288,10 +293,7 @@ class GlancesCursesBrowser(_GlancesCurses): self.cursor = len(stats) - 1 start_line = self._page_max_lines * self._current_page - end_line = start_line + self._page_max_lines - if end_line > stats_len: - end_line = stats_len - + end_line = start_line + self.get_pagelines(stats) current_page = stats[start_line:end_line] # Display table