Close another program when main script is closed

18 Views Asked by At

I have a python script that opens an executable. My goal is to have the executable close automatically when the main script is closed.

This is what I have so far (partly from chat-gpt). However, terminate_win never gets called.

def terminate_win(sig, frame):
    proc.terminate()
    sys.exit(0)

def handle_deliveries():
    global proc
    try:
        signal.signal(signal.SIGTERM, terminate_win)
        signal.signal(signal.SIGINT, terminate_win)
        current_directory = os.path.dirname(os.path.abspath(__file__))
        proc = subprocess.Popen([current_directory + "/scripts/alg-window.exe"])
    except Exception as e: 
        print(e)
0

There are 0 best solutions below