Skip to content

Commit

Permalink
Merge pull request #202 from lowar/catch_sigterm
Browse files Browse the repository at this point in the history
Add a SIGTERM handler to gracefully shutdown running app
  • Loading branch information
bohdan-s authored Oct 28, 2024
2 parents 9364a6c + 7418ebb commit 1eea31f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SunGather/sungather.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import getopt
import yaml
import time
import signal

def main():
configfilename = 'config.yaml'
Expand Down Expand Up @@ -145,6 +146,8 @@ def main():

scan_interval = config_inverter.get('scan_interval')

signal.signal(signal.SIGTERM, handle_sigterm)

# Core polling loop
while True:
loop_start = time.perf_counter()
Expand Down Expand Up @@ -181,6 +184,11 @@ def main():
logging.info(f'Next scrape in {int(scan_interval - process_time)} secs')
time.sleep(scan_interval - process_time)

def handle_sigterm(signum, frame):
print("Received SIGTERM, shutting down gracefully...")
# Perform any cleanup here
exit(0)

logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.DEBUG,
Expand Down

0 comments on commit 1eea31f

Please sign in to comment.