Git Product home page Git Product logo

Comments (3)

eryksun avatar eryksun commented on June 12, 2024

With shell=True, the script signals the shell (e.g. bash), which will ignore SIGINT. In this case, SIGABRT kills the shell and leaves the sleep 1d command running. To send SIGINT to the child of the shell as well, execute the shell as the group leader of a new process group by passing the Popen argument process_group=0, and signal the group via os.killpg(process.pid, signal.SIGINT).

from cpython.

EricCousineau-TRI avatar EricCousineau-TRI commented on June 12, 2024

Thanks! Yup, that worked.
I had to slightly change your suggestion, using https://stackoverflow.com/a/22582659/7829525 + looking at this code:
https://github.com/python/cpython/blob/v3.10.12/Modules/_posixsubprocess.c#L554-L555

Using Popen(*, start_new_session=True) and os.killpg(os.getpgid(process.pid), signal.SIGINT) seems to fix it.
Patch applied to code similar to above:
EricCousineau-TRI/repro@f2aca66

from cpython.

eryksun avatar eryksun commented on June 12, 2024

The process_group option was added in 3.11. Using a new process group is my preferred way to solve this for a non-interactive process. Creating a new session works as well. Note that with a new session, the child process won't have a controlling terminal (e.g. opening "/dev/tty" will fail), but that shouldn't matter for a non-interactive command.

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.