Skip to content

Signals not forwarded to child processes #3789

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

Open
2 tasks done
jonashaag opened this issue May 19, 2025 · 2 comments · May be fixed by #3837
Open
2 tasks done

Signals not forwarded to child processes #3789

jonashaag opened this issue May 19, 2025 · 2 comments · May be fixed by #3837
Assignees
Labels
bug Something isn't working

Comments

@jonashaag
Copy link

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

pixi run python sig.py
kill -INT <pixi run PID>
kill -INT <python PID>

Issue description

When you send a signal to the pixi parent process it's not forwarded to the child.

import signal
import time

def signal_handler(signum, frame):
    print(f"Signal handler called with signal {signum}")

signal.signal(signal.SIGINT, signal_handler)

while True:
    time.sleep(1)

Expected behavior

Should forward signals

@jonashaag jonashaag added the bug Something isn't working label May 19, 2025
@ruben-arts ruben-arts assigned baszalmstra and wolfv and unassigned baszalmstra May 20, 2025
Copy link
Member

wolfv commented May 22, 2025

I did investigate this issue a bit and CTRL+C in the terminal works fine on macOS - and I think we would have heard about this more otherwise 🙂

What does indeed not work properly is to send a signal with kill to the pixi run process.

Sending the signal with kill to the child process of pixi works fine. Not sure how to properly fix this yet.

@stammler
Copy link

stammler commented May 25, 2025

I have the same issue with signals not being forwarded to child processes in pixi run.

My use case is a SLURM job that is sending signals shortly before the timeout to let the program safely exit.

Here is a minimum working example:

The SLURM batch file looks as follows and sends SIGTERM 60 seconds before the timeout.

#!/bin/zsh
#SBATCH --job-name=test
#SBATCH .
#SBATCH .
#SBATCH .
#SBATCH --time=00:03:00
#SBATCH --signal=B:15@60
#SBATCH --output=job_%x_%j.out

export PYTHONUNBUFFERED=1
exec ~/.pixi/envs/default/bin/python test.py   # <--- works
exec pixi run python test.py                   # <--- does not work

This is the test.py file:

import signal
import time
import sys
import os

def handler(signum, frame):
    print(f"[{time.ctime()}] Received signal {signum}, saving state and exiting.")
    sys.stdout.flush()
    time.sleep(1)
    sys.exit(0)

signal.signal(signal.SIGTERM, handler)

print(f"PID: {os.getpid()}")
print(f"[{time.ctime()}] Simulation starting...")
sys.stdout.flush()

# Some long-running job
for i in range(300):
    print(f"Step {i}")
    sys.stdout.flush()
    time.sleep(1)

Are there any plans of forwarding signals to the child processes?

@wolfv wolfv linked a pull request May 26, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants