The script:
#!/usr/bin/python3
import os
temp = os.system("nvidia-settings -q gpucoretemp -t")
if temp <= 40:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=30")
elif temp >= 41 and temp <= 50:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=35")
elif temp >= 51 and temp <= 55:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=40")
elif temp >= 56 and temp <= 60:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=50")
elif temp >= 61 and temp <= 70:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=65")
elif temp >= 71 and temp <= 80:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=75")
elif temp >= 81 and temp <= 90:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=90")
else:
os.system("nvidia-settings -a [fan:0]/GPUCurrentFanSpeed=100")
When I run "nvidia-settings -q gpucoretemp -t" by itself in the Linux terminal it outputs a temperature (Ex. 53) but when I use the command in my script and assign it to a variable it would saves as:
53 0
The 0 is throwing off my script and making the fan change to 30% instead of 40%.
Why is it putting a 0 in the output when I use the command in my Python script and how do I make it only save the 53 (or other temperature)?


Sign In
Create Account


Back to top









