79792752

Date: 2025-10-17 05:09:23
Score: 0.5
Natty:
Report link
import signal
import sys

def handle_sigterm(signum, frame):
    """
    Signal handler for graceful shutdown.
    Triggered when the process receives SIGTERM or SIGINT.
    """
    print("Received shutdown signal, cleaning up...")

    # Attempt to stop running browser processes gracefully.
    # You can extend this list with any other browser names you use.
    for b in ("firefox","edge"):
        try:
            stop_function(b)  # user-defined cleanup function
        except Exception:
            # Ignore any errors during cleanup to ensure shutdown continues
            pass

    # Exit the process cleanly
    sys.exit(0)

# Register the handler for termination (SIGTERM) and interrupt (SIGINT / Ctrl+C)
signal.signal(signal.SIGTERM, handle_sigterm)
signal.signal(signal.SIGINT, handle_sigterm)
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Harini David