Skip to content

Commit

Permalink
Backport signal handler to Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaggioni committed May 25, 2020
1 parent 4cafd32 commit 645258d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions fan_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,14 @@ def main():


def graceful_shutdown(signalnum, frame):
strsignal = signal.strsignal(signalnum)
print(f"setting hosts back to automatic fan control because we received the signal: {strsignal}")

print("Signal {} received, giving up control".format(signalnum))
for host in config['hosts']:
set_fan_control("automatic", host)

sys.exit(0)


if __name__ == "__main__":
# Register signal handler on SIGTERM to do a graceful shutdown
# Reset fan control to automatic when getting killed
signal.signal(signal.SIGTERM, graceful_shutdown)

try:
Expand Down

0 comments on commit 645258d

Please # to comment.