Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] On Librem5 psutil crash #1919

Closed
nokernel opened this issue Feb 19, 2021 · 1 comment
Closed

[Linux] On Librem5 psutil crash #1919

nokernel opened this issue Feb 19, 2021 · 1 comment
Labels

Comments

@nokernel
Copy link

nokernel commented Feb 19, 2021

Summary

  • OS: Linux Librem5 PureOS amber-phone
  • Architecture: arm64
  • Psutil version: 5.8.0
  • Python version: 3.8.6
  • Type:crash

Description

Issues when using bpytop on Librem5 phone 1st I reported the issue there.

But looks like it's in psutil. I was able to hack it to work by changing psutil line 1455 with secsleft = int(int(energy_now) / int(power_now) * 3600)

Psutil does a / between int and bytes causing error and crash.

  File "/home/purism/.asdf/installs/python/3.8.6/lib/python3.8/site-packages/psutil/__init__.py", line 2288, in sensors_battery
    return _psplatform.sensors_battery()
  File "/home/purism/.asdf/installs/python/3.8.6/lib/python3.8/site-packages/psutil/_pslinux.py", line 1455, in sensors_battery
    secsleft = int(energy_now / power_now * 3600)
TypeError: unsupported operand type(s) for /: 'int' and 'bytes'
@nokernel nokernel added the bug label Feb 19, 2021
@nokernel nokernel changed the title [PureOS] On Librem5 psutil crash [linux] On Librem5 psutil crash Feb 24, 2021
@nokernel nokernel changed the title [linux] On Librem5 psutil crash [Linux] On Librem5 psutil crash Feb 24, 2021
@asmca
Copy link

asmca commented Dec 4, 2021

it also happens on other devices that shows 'current_now' item value NEGTIVE.

suse@suse-lc:$ uname -a
Linux suse-lc 4.19.71-arm64-desktop #1 SMP PREEMPT Thu Jul 15 14:18:15 CST 2021 aarch64 GNU/Linux
suse@suse-lc:
$ cat /sys/class/power_supply/Battery/current_now
-634000


As mentioned in : https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power

the negtive value may means:"Valid values: Represented in microamps. Negative values are used for discharging batteries,"


the problem is that "isdigit()" function failed on negtive number:
EX:

"5".isdigit()
True
"-5".isdigit()
False

above fix avoids using "isdigit()" function, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants