Merge pull request #2832 from nicolargo/2831-j-hot-key-crashs-glances

fix: plugin (processlist) - failure on programs view
This commit is contained in:
RazCrimson 2024-06-15 05:49:58 +05:30 committed by GitHub
commit 78b4518547
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -324,31 +324,34 @@ class PluginModel(GlancesPluginModel):
def _get_process_curses_time(self, p, selected, args): def _get_process_curses_time(self, p, selected, args):
"""Return process time curses""" """Return process time curses"""
cpu_times = p['cpu_times']
try: try:
# Sum user and system time # Sum user and system time
user_system_time = p['cpu_times']['user'] + p['cpu_times']['system'] user_system_time = cpu_times['user'] + cpu_times['system']
except (OverflowError, TypeError): except (OverflowError, TypeError, KeyError):
# Catch OverflowError on some Amazon EC2 server # Catch OverflowError on some Amazon EC2 server
# See https://github.com/nicolargo/glances/issues/87 # See https://github.com/nicolargo/glances/issues/87
# Also catch TypeError on macOS # Also catch TypeError on macOS
# See: https://github.com/nicolargo/glances/issues/622 # See: https://github.com/nicolargo/glances/issues/622
# Also catch KeyError (as no stats be present for processes of other users)
# See: https://github.com/nicolargo/glances/issues/2831
# logger.debug("Cannot get TIME+ ({})".format(e)) # logger.debug("Cannot get TIME+ ({})".format(e))
msg = self.layout_header['time'].format('?') msg = self.layout_header['time'].format('?')
ret = self.curse_add_line(msg, optional=True) return self.curse_add_line(msg, optional=True)
hours, minutes, seconds = seconds_to_hms(user_system_time)
if hours > 99:
msg = f'{hours:<7}h'
elif 0 < hours < 100:
msg = f'{hours}h{minutes}:{seconds}'
else: else:
hours, minutes, seconds = seconds_to_hms(user_system_time) msg = f'{minutes}:{seconds}'
if hours > 99:
msg = f'{hours:<7}h' msg = self.layout_stat['time'].format(msg)
elif 0 < hours < 100: if hours > 0:
msg = f'{hours}h{minutes}:{seconds}' return self.curse_add_line(msg, decoration='CPU_TIME', optional=True)
else:
msg = f'{minutes}:{seconds}' return self.curse_add_line(msg, optional=True)
msg = self.layout_stat['time'].format(msg)
if hours > 0:
ret = self.curse_add_line(msg, decoration='CPU_TIME', optional=True)
else:
ret = self.curse_add_line(msg, optional=True)
return ret
def _get_process_curses_thread(self, p, selected, args): def _get_process_curses_thread(self, p, selected, args):
"""Return process thread curses""" """Return process thread curses"""