提交 41f48265 编写于 作者: S sangoh.hong

Client Browser's thread management added.

Curses Browser's key bug fixed.
上级 8aecac8f
......@@ -47,3 +47,6 @@ _build
# web ui
node_modules/
bower_components/
# visual stdio code
.vscode/
\ No newline at end of file
......@@ -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.
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册