summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan <yan@metatem.net>2021-05-31 15:33:23 +0200
committerYan <yan@metatem.net>2021-06-07 16:39:31 +0200
commit9d64cafaa498753eabe2560615c3036ff8321ec4 (patch)
tree849cd2bf28863cd14f91f8a242caf3753ab2f1de
parent2207e9be81f5eff1e078118cef122f2747cc76f7 (diff)
Fix history_add, so it allows history_max_size to be zero
It was trying to pop from an empty list when history_max_size was zero.
-rw-r--r--glances/attribute.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/glances/attribute.py b/glances/attribute.py
index f73c8737..8a6f2b5a 100644
--- a/glances/attribute.py
+++ b/glances/attribute.py
@@ -21,7 +21,6 @@
from datetime import datetime
-
class GlancesAttribute(object):
def __init__(self, name, description='', history_max_size=None):
@@ -105,10 +104,10 @@ class GlancesAttribute(object):
def history_add(self, value):
"""Add a value in the history
"""
- if not (self._history_max_size is None or self.history_len() < self._history_max_size):
- #self._history = self._history[1:] + [value]
- self._history.pop(0)
- self._history.append(value)
+ if self._history_max_size:
+ if self.history_len() >= self._history_max_size:
+ self._history.pop(0)
+ self._history.append(value)
def history_size(self):
"""Return the history size (maximum nuber of value in the history)