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

sensors_temperatures() return {} on my CentOS system #971

Closed
nicolargo opened this issue Feb 4, 2017 · 13 comments
Closed

sensors_temperatures() return {} on my CentOS system #971

nicolargo opened this issue Feb 4, 2017 · 13 comments
Labels

Comments

@nicolargo
Copy link
Contributor

On my CentOS 7.1 system with PsUtil 5.1.2.

I have the following sensors:

$ ll /sys/class/hwmon/hwmon0/device/temp*
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp1_crit
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp1_crit_alarm
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp1_input
-r--r--r-- 1 root root 4096 24 janv. 13:27 /sys/class/hwmon/hwmon0/device/temp1_label
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp1_max
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp2_crit
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp2_crit_alarm
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp2_input
-r--r--r-- 1 root root 4096 24 janv. 13:27 /sys/class/hwmon/hwmon0/device/temp2_label
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp2_max
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp3_crit
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp3_crit_alarm
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp3_input
-r--r--r-- 1 root root 4096 24 janv. 13:27 /sys/class/hwmon/hwmon0/device/temp3_label
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp3_max
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp4_crit
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp4_crit_alarm
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp4_input
-r--r--r-- 1 root root 4096 24 janv. 13:27 /sys/class/hwmon/hwmon0/device/temp4_label
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp4_max
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp5_crit
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp5_crit_alarm
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp5_input
-r--r--r-- 1 root root 4096 24 janv. 13:27 /sys/class/hwmon/hwmon0/device/temp5_label
-r--r--r-- 1 root root 4096 23 janv. 15:20 /sys/class/hwmon/hwmon0/device/temp5_max

But sensors_temperatures() return {}:

$ ipython
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import psutil

In [2]: psutil.sensors_temperatures()
Out[2]: {}
@sethmlarson
Copy link

It's because of this line in psutil/_pslinux.py:

    basenames = sorted(set(
        [x.split('_')[0] for x in
         glob.glob('/sys/class/hwmon/hwmon*/temp*_*')]))

I'll submit a PR to fix this issue.

@giampaolo
Copy link
Owner

This makes me sad. I wonder why /sys/class/hwmon/ differs like this.
@SethMichaelLarson your PR breaks on my Ubuntu 16.04 which has no "device" intermediate directory.

@sethmlarson
Copy link

sethmlarson commented Feb 4, 2017

Doesn't /**/ in a glob pattern include no directory?

@giampaolo
Copy link
Owner

No. :( It's probably best to use os.walk and filter for file names starting with "temp_*" so that the tree depth doesn't matter.

@sethmlarson
Copy link

Dang! I could probably whip something up using os.walk. Probably would be a lot more efficient than just globbing with a star pattern anyways.

@giampaolo
Copy link
Owner

Performance isn't really a concern in this case. The whole tree should be way less than 100 files/dirs in total.

@giampaolo
Copy link
Owner

Can you try 561f32a?
I don't really like it as a solution but I can't think of anything better.

I ruled out os.walk because there are symlinks making the whole tree too big to parse. After all you were right: os.walk is too slow.

@sethmlarson
Copy link

sethmlarson commented Feb 5, 2017

@giampaolo I figured, os.walk is a os.listdir call for each directory and an os.stat call for each file and directory. They made os.scandir for a reason! :P Glad you found something that works faster. :)

@giampaolo
Copy link
Owner

So did you test this? Does it work?

@sethmlarson
Copy link

@giampaolo I don't have a CentOS system. User who opened the issue does.

@nicolargo
Copy link
Contributor Author

@giampaolo Works like a wharm on my CentOS 7.1 system:

In [1]: import psutil

In [2]: psutil.sensors_temperatures()
Out[2]: 
{'coretemp': [shwtemp(label='Physical id 0', current=34.0, high=80.0, critical=98.0),
  shwtemp(label='Core 0', current=31.0, high=80.0, critical=98.0),
  shwtemp(label='Core 1', current=34.0, high=80.0, critical=98.0),
  shwtemp(label='Core 2', current=33.0, high=80.0, critical=98.0),
  shwtemp(label='Core 3', current=32.0, high=80.0, critical=98.0)]}

@giampaolo
Copy link
Owner

Cool. I will package a 5.1.3 version soon.

@giampaolo
Copy link
Owner

OK, new version is out.

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

No branches or pull requests

3 participants