Skip to content

Commit

Permalink
Merge pull request #4 from bernhofer/main
Browse files Browse the repository at this point in the history
added SIGTERM signal handler for main loop
  • Loading branch information
RoversX authored Nov 11, 2024
2 parents a4eeea1 + fc1d3d3 commit d6c18c7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion nvidia_fan_control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from pynvml import *
import os
import signal

# Fan curve parameters
temperature_points = [0, 40, 57, 70]
Expand Down Expand Up @@ -122,8 +123,18 @@ def print_info(info):

# Main loop
last_lines = 0
terminate = False

# Handler to terminate main loop
def signal_handler(sig, frame):
global terminate
terminate = True

# Register signal handler to gracefully shutdown
signal.signal(signal.SIGTERM, signal_handler)

try:
while True:
while not terminate:
for handle, fan_count in zip(handles, fan_counts):
# get the temperature
temperature = nvmlDeviceGetTemperature(handle, NVML_TEMPERATURE_GPU)
Expand Down

0 comments on commit d6c18c7

Please sign in to comment.