Comments (3)
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.
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.
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)
- Add `asyncio.Queue.__aiter__` HOT 9
- Needs of feature that disabling optimization pipeline in runtime
- Make timeit CLI function available from python HOT 3
- Improve performance of `os.walk()` HOT 1
- [Windows] High DPI causes tkinter turtledemo windows blurry
- `clear` method of `list` class in `multiprocessing.Manager()` is missing HOT 2
- inconsistent bahaviour of `functools.partial` python and C HOT 1
- Implement PEP 649
- [C API] Add an efficient public PyUnicodeWriter API HOT 23
- ipython breaks on Python-3.13.0b1 when a 'tempfilepager' is not defined HOT 4
- Mention `all()` & `any()` are only efficient for existing iterables HOT 7
- Fraction wrongfully gets casted into float when given as argument to __rpow__ HOT 13
- [Doc] no documentation for async with HOT 1
- `SLOW_SUM` flag in `sum` builtin HOT 2
- trying mypyc on Cython-3.1.0a1 with Python-3.13.0b1 I get a "this header requires Py_BUILD_CORE define" HOT 10
- Warning on autocomplete messes up the terminal HOT 13
- getargs.c is Breaking Interpeter Isolation HOT 4
- Remove legacy TODOs from code. HOT 4
- Add `posixpath.isreserved()` HOT 19
- Python/flowgraph.c:528: _Bool all_exits_have_lineno(basicblock *): Assertion `0' failed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.