[Python] Is the following process-killing strategy sound? [closed]

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have a python program which is called many times. In some cases I want to kill some of those instances, and any child subprocesses they might have spawned.

    So what I do right now is:

    import os
    # Ensure we get a brand new group process id
    os.setsid()
    group_process_id = os.getpgid(0)
    child_process = subprocess.run(
    cmd,
    process_group=current_pgid,
    )
    ...


    then when I want to kill that python program, I get it input its group process id, and just call os.killpg(process_group_id, signal.SIGKILL)

    Is this approach sound, or would it leave zombie processes in my OS?

    Continue reading...

Compartilhe esta Página