Comments (5)
It's not clear to me what you are actually attempting to do. What is your use case? It looks like you want a process to succeed even though it was SIGKILL'ed:
import signal
import sh
sh.sleep(999, _ok_code=[signal.SIGKILL])
SIGNALS_THAT_SHOULD_THROW_EXCEPTION
is not meant for general consumption and cannot be altered.
from sh.
Ah, sorry, I should have specified. You're correct: I want no exception to be raised when I send SIGKILL (or SIGTERM, or whatever) to a specific process. My actual use case:
- start
pavumeter
in the background to monitor audio levels for a stream - start
parec
andffmpeg
in the foreground to record audio from that stream - when done recording, kill
pavumeter
and proceed with the rest of the script (without forcing the user to manually closepavumeter
)
I'm not suggesting modifying SIGNALS_THAT_SHOULD_THROW_EXCEPTION
: that should stay as it is. I would just like the -9
(or -signal.SIGKILL
) in _ok_code
to be honored, which seemed to be possible until that commit in 2016 (accidentally?) removed the ability to do so.
There's maybe a conversation to be had on how to make signal allowlisting more intuitive, since the only mention of them just being negative exit codes is in the Architecture document, but not allowing them at all feels more confusing to me.
from sh.
SIGNALS_THAT_SHOULD_THROW_EXCEPTION
is not meant for general consumption and cannot be altered.
Just to further clarify, the code snippet in the first post was just me using the Python REPL to create a minimal reproduction of the issue, showing that the pre- and post-simplification conditions for the if
in get_exc_exit_code_would_raise
are not equivalent.
The "simplified" condition returns True
, and causes an exception to be raised even if -9
is one of the allowlisted exit codes:
>>> not success or bad_sig
True
Whereas the pre-e98004c condition returns False
, allowing me to ignore -9
if I so choose:
>>> exit_code not in ok_codes and (exit_code > 0 or -exit_code in
... SIGNALS_THAT_SHOULD_THROW_EXCEPTION)
False
from sh.
Thanks for sleuthing @iamjackg. It indeed looks like a regression that nobody has noticed in 7 years. I'm kind of surprised there was no test case for this. It sounds like the fix is to revert back to the old logic (but make it easier to read), add a test, and add some documentation. If you agree, would you be willing to take a crack at it?
from sh.
I'd love to, not sure when I'll have time, so if you get to this first by all means go for it.
from sh.
Related Issues (20)
- RFE: please start making github releases HOT 6
- Automate github releases
- cannot import name 'pg_dump' from 'sh' HOT 2
- Github page link 404s HOT 2
- glob wrapper breaks glob(.., root_dir=someething) HOT 1
- Special kwarg _cwd and sh.pushd() not working HOT 5
- baking piped commands HOT 2
- piped commands via ssh? HOT 4
- RFH: Unable to pipe `sudo` process to `sudo` process HOT 3
- sh doesn't print output unless wrapped in print() HOT 1
- Feature proposal: _except callback HOT 6
- documentation has bad example code HOT 1
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- Mention `pbs3` as an alternative for Windows? HOT 4
- Info pushed to stdout instead of variable when invoked with contirb.sudo HOT 6
- sh 1.14.3 breaks isinstance(sh.command_name, sh.Command) HOT 2
- Idiomatic way of handling binary data from commands? HOT 3
- Monkey patch of glob.glob breaks root_dir kwarg HOT 4
- Add GitHub release for 2.0.7 HOT 3
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 sh.