Repository: ultrabug/py3status

Issue:
Sysdata module crash  (red Sysdata: 'SReclaimable:' ) on raspberry Pi4  (using rasbian)
Problem: py3status shows red Sysdata: 'SReclaimable:'  instead of requested info.

When running module directly I captured traceback:

> 'SReclaimable:' (KeyError) module.py line 940.
> Traceback
> KeyError: 'SReclaimable:'
>   File "/usr/local/lib/python3.7/dist-packages/py3status/module.py", line 940, in run
>     response = method()
>   File "sysdata.py", line 487, in sysdata
>     mem = self._calc_mem_info(self.mem_unit, meminfo, True)
>   File "sysdata.py", line 347, in _calc_mem_info
>     + (meminfo["SReclaimable:"] - meminfo["Shmem:"])

Printed out meminfo keys:

`dict_keys(['MemTotal:', 'MemFree:', 'MemAvailable:', 'Buffers:', 'Cached:', 'SwapCached:', 'Active:', 'Inactive:', 'Active(anon):', 'Inactive(anon):', 'Active(file):', 'Inactive(file):', 'Unevictable:', 'Mlocked:', 'HighTotal:', 'HighFree:', 'LowTotal:', 'LowFree:', 'SwapTotal:', 'SwapFree:', 'Dirty:', 'Writeback:', 'AnonPages:', 'Mapped:'])`

/proc/meminfo content

> pi@raspberrypi:~ $ cat /proc/meminfo
> MemTotal:        3918788 kB
> MemFree:         1219532 kB
> MemAvailable:    2251752 kB
> Buffers:          123572 kB
> Cached:          1341312 kB
> SwapCached:            0 kB
> Active:          1487936 kB
> Inactive:         851568 kB
> Active(anon):    1078656 kB
> Inactive(anon):   141260 kB
> Active(file):     409280 kB
> Inactive(file):   710308 kB
> Unevictable:      191952 kB
> Mlocked:              48 kB
> HighTotal:       3263488 kB
> HighFree:         825476 kB
> LowTotal:         655300 kB
> LowFree:          394056 kB
> SwapTotal:        102396 kB
> SwapFree:         102396 kB
> Dirty:               264 kB
> Writeback:             0 kB
> AnonPages:       1066536 kB
> Mapped:           338436 kB
> Shmem:            345308 kB
> KReclaimable:      65548 kB
> Slab:              92696 kB
> SReclaimable:      65548 kB
> SUnreclaim:        27148 kB
> KernelStack:        3592 kB
> PageTables:        20852 kB
> NFS_Unstable:          0 kB
> Bounce:                0 kB
> WritebackTmp:          0 kB
> CommitLimit:     2061788 kB
> Committed_AS:    4465924 kB
> VmallocTotal:     245760 kB
> VmallocUsed:        5252 kB
> VmallocChunk:          0 kB
> Percpu:              464 kB
> CmaTotal:         262144 kB
> CmaFree:          226036 kB

For fast quickfix I removed line:
https://github.com/ultrabug/py3status/blob/8fa69124ec13106fd21bec27bd77f6c5045c5803/py3status/modules/sysdata.py#L347

Versions:

> i3 version 4.16.1 (2019-01-27) © 2009 Michael Stapelberg and contributors
>  py3status version 3.30 (python 3.7.3) on i3   (same issue happens when running dev version module)
> i3status 2.12 (2018-05-11) © 2008 Michael Stapelberg and contributors


Sysdata module crash  (red Sysdata: 'SReclaimable:' ) on raspberry Pi4  (using rasbian)
Problem: py3status shows red Sysdata: 'SReclaimable:'  instead of requested info.

When running module directly I captured traceback:

> 'SReclaimable:' (KeyError) module.py line 940.
> Traceback
> KeyError: 'SReclaimable:'
>   File "/usr/local/lib/python3.7/dist-packages/py3status/module.py", line 940, in run
>     response = method()
>   File "sysdata.py", line 487, in sysdata
>     mem = self._calc_mem_info(self.mem_unit, meminfo, True)
>   File "sysdata.py", line 347, in _calc_mem_info
>     + (meminfo["SReclaimable:"] - meminfo["Shmem:"])

Printed out meminfo keys:

`dict_keys(['MemTotal:', 'MemFree:', 'MemAvailable:', 'Buffers:', 'Cached:', 'SwapCached:', 'Active:', 'Inactive:', 'Active(anon):', 'Inactive(anon):', 'Active(file):', 'Inactive(file):', 'Unevictable:', 'Mlocked:', 'HighTotal:', 'HighFree:', 'LowTotal:', 'LowFree:', 'SwapTotal:', 'SwapFree:', 'Dirty:', 'Writeback:', 'AnonPages:', 'Mapped:'])`

/proc/meminfo content

> pi@raspberrypi:~ $ cat /proc/meminfo
> MemTotal:        3918788 kB
> MemFree:         1219532 kB
> MemAvailable:    2251752 kB
> Buffers:          123572 kB
> Cached:          1341312 kB
> SwapCached:            0 kB
> Active:          1487936 kB
> Inactive:         851568 kB
> Active(anon):    1078656 kB
> Inactive(anon):   141260 kB
> Active(file):     409280 kB
> Inactive(file):   710308 kB
> Unevictable:      191952 kB
> Mlocked:              48 kB
> HighTotal:       3263488 kB
> HighFree:         825476 kB
> LowTotal:         655300 kB
> LowFree:          394056 kB
> SwapTotal:        102396 kB
> SwapFree:         102396 kB
> Dirty:               264 kB
> Writeback:             0 kB
> AnonPages:       1066536 kB
> Mapped:           338436 kB
> Shmem:            345308 kB
> KReclaimable:      65548 kB
> Slab:              92696 kB
> SReclaimable:      65548 kB
> SUnreclaim:        27148 kB
> KernelStack:        3592 kB
> PageTables:        20852 kB
> NFS_Unstable:          0 kB
> Bounce:                0 kB
> WritebackTmp:          0 kB
> CommitLimit:     2061788 kB
> Committed_AS:    4465924 kB
> VmallocTotal:     245760 kB
> VmallocUsed:        5252 kB
> VmallocChunk:          0 kB
> Percpu:              464 kB
> CmaTotal:         262144 kB
> CmaFree:          226036 kB

For fast quickfix I removed line:
https://github.com/ultrabug/py3status/blob/8fa69124ec13106fd21bec27bd77f6c5045c5803/py3status/modules/sysdata.py#L347

Versions:

> i3 version 4.16.1 (2019-01-27) © 2009 Michael Stapelberg and contributors
>  py3status version 3.30 (python 3.7.3) on i3   (same issue happens when running dev version module)
> i3status 2.12 (2018-05-11) © 2008 Michael Stapelberg and contributors




Discussion:
Found out a root cause for this issue:
https://github.com/ultrabug/py3status/blob/8fa69124ec13106fd21bec27bd77f6c5045c5803/py3status/modules/sysdata.py#L378

Different platforms have different length for /proc/meminfo.

For example.
Pi  has total 42 lines and SReclaimable is at line 28
Digitalocean server has 46 lines and SReclaimable is at line 23
Another server has total 36 lines and SReclaimable is at line 23

Helpful git blame forwaded me to pull request: #1697
I agree with general idea but "head" vairable should calculated dynamically.

Make a PR. Bumping the head up to `28` ought to be good enuff.
Found out a root cause for this issue:
https://github.com/ultrabug/py3status/blob/8fa69124ec13106fd21bec27bd77f6c5045c5803/py3status/modules/sysdata.py#L378

Different platforms have different length for /proc/meminfo.

For example.
Pi  has total 42 lines and SReclaimable is at line 28
Digitalocean server has 46 lines and SReclaimable is at line 23
Another server has total 36 lines and SReclaimable is at line 23

Helpful git blame forwaded me to pull request: #1697
I agree with general idea but "head" vairable should calculated dynamically.

Make a PR. Bumping the head up to `28` ought to be good enuff.

Resolving patch:
diff --git a/py3status/modules/sysdata.py b/py3status/modules/sysdata.py
--- a/py3status/modules/sysdata.py
+++ b/py3status/modules/sysdata.py
@@ -375,7 +375,7 @@ def _calc_mem_info(self, unit, meminfo, memory):
             free_percent,
         )
 
-    def _get_meminfo(self, head=24):
+    def _get_meminfo(self, head=28):
         with open("/proc/meminfo") as f:
             info = [line.split() for line in (next(f) for x in range(head))]
             return {fields[0]: float(fields[1]) for fields in info}


Test patch: