diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-08 21:26:33 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-08 21:26:33 +0200 |
commit | 09a8258ba06c068f32f8c66518c93666cfed5d0a (patch) | |
tree | 069f35f44ba531ba785f4b23221566a2706e9308 | |
parent | 5141848f0e607c5894733297c46755be41af975c (diff) | |
download | psutil-09a8258ba06c068f32f8c66518c93666cfed5d0a.tar.gz |
#802: remove entries from index dict
-rw-r--r-- | psutil/_common.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/psutil/_common.py b/psutil/_common.py index bdfcefcd..d26d0ff0 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -481,8 +481,19 @@ def wrap_numbers(input_dict, name): _wrapn_cache[name] = input_dict return input_dict - new_dict = {} + # In case the number of keys changed between calls (e.g. a + # disk disappears) this removes the entry from _wrapn_reminders. + # TODO: this is messy; change the algorithm. old_dict = _wrapn_cache[name] + gone_keys = set(old_dict.keys()) - set(input_dict.keys()) + if gone_keys: + for gone_key in gone_keys: + for k in _wrapn_reminders.keys(): + nam, key, i = k + if nam == name and key == gone_key: + del _wrapn_reminders[k] + + new_dict = {} for key in input_dict.keys(): input_nt = input_dict[key] try: |