[Python] End Python script when all apps that it has opened are closed

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python script that opens 4 different programs. Is there a way to code in the script that it should stop when these programs close?

    Currently it just hangs open and I have to use ctrl+c to stop it but would be nice to automate it.

    Here's my code:

    import os
    import sys
    import subprocess
    from subprocess import Popen

    def back_insert(filename):
    #inserts backslashes into paths that have spaces in them
    flist = list(filename)
    i = 0

    while i < len(flist):
    if flist == " ":
    flist.insert(i, "\\")
    i += 2

    else: i += 1

    fstring = "".join(flist)

    return fstring

    #set full Path to Emulator Executable:
    game = back_insert("/usr/bin/snes9x-gtk")

    #set full Path to your Tracker:
    tracker = back_insert("/usr/share/OpenTracker/OpenTracker")

    #set full Path to Qusb or SNI:
    wsocket = back_insert("/bin/QUsb2Snes")

    #set full Path to your Timer:
    counter = back_insert("/home/user/LibreSplit/libresplit")

    #Runs the Emulator, socket, Timer and Tracker
    commands = [wsocket, counter, tracker, game]
    procs = [Popen(i) for i in commands]
    for p in procs:
    p.wait()

    Continue reading...

Compartilhe esta Página