Created
August 1, 2013 16:19
-
-
Save zielmicha/6132904 to your computer and use it in GitHub Desktop.
Suspend if your CPU is getting too hot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sensors | |
import subprocess | |
import time | |
def emergency(): | |
subprocess.check_call(['sudo', 'pm-suspend']) | |
def watch(): | |
while True: | |
if need_emergency(): | |
emergency() | |
time.sleep(5) | |
time.sleep(1) | |
def need_emergency(): | |
for feature in used_features: | |
if feature.get_value() > 90: | |
return True | |
return False | |
def main(): | |
global used_features | |
sensors.init() | |
try: | |
used_features = [] | |
for chip in sensors.iter_detected_chips(): | |
for feature in chip: | |
used_features.append(feature) | |
watch() | |
finally: | |
sensors.cleanup() | |
if __name__ == '__main__': | |
import daemonize | |
daemon = daemonize.Daemonize(app="tempwatch", pid='/var/run/tempwatch.log', action=main) | |
daemon.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment