Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suprocesses are not properly cleaned up #49

Open
thetheodor opened this issue Dec 6, 2022 · 4 comments
Open

Suprocesses are not properly cleaned up #49

thetheodor opened this issue Dec 6, 2022 · 4 comments

Comments

@thetheodor
Copy link
Member

We need to send death signals to subprocesses (e.g., creduce's sigterm)

@thetheodor
Copy link
Member Author


import os
import signal

os.setpgrp()

def cleanup(signum, frame):
    os.killpg(0, signal.SIGKILL)```

@thetheodor
Copy link
Member Author

thetheodor commented Sep 8, 2023

chatgpt suggests:

You can set subprocess.Popen parameter start_new_session=False and attach a signal handler to the parent process to forward signals like SIGTERM and SIGINT to the child processes.

Example:

import subprocess
import signal
import os

def signal_handler(signum, frame):
    for p in child_processes:
        p.send_signal(signum)

signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)

child_processes = []

# Launch subprocess
p = subprocess.Popen(["your_command"], start_new_session=False)
child_processes.append(p)

# Your main program logic here

This ensures that when the parent receives SIGTERM or SIGINT, it forwards the signal to the child processes for cleanup.

diopter.Reducer 
 |
 | - python.subprocesss[creduce]   <--- creduce kills its subprocesses
         |
         |- creduce.subprocess1
         |  |
         |  |- python.reducer_callback
         |       |
         |       |-> python.subprocess[gcc/whatever]  <--------- the signal must be propagated here
         |
         |- creduce.subprocess2
         |- ...
         |- creduce.subprocessn

@thetheodor
Copy link
Member Author

@shao-hua-li is this still a problem for you?

@shao-hua-li
Copy link
Collaborator

Sometime yes, but is already rare for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants