Coder Social home page Coder Social logo

Comments (5)

ecederstrand avatar ecederstrand commented on July 17, 2024

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.

iamjackg avatar iamjackg commented on July 17, 2024

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 and ffmpeg 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 close pavumeter)

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.

iamjackg avatar iamjackg commented on July 17, 2024

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.

amoffat avatar amoffat commented on July 17, 2024

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.

iamjackg avatar iamjackg commented on July 17, 2024

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)

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.