Skip to content
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

exp_sig always assumes full POSIX compliance of the called executable #457

Closed
languitar opened this issue May 10, 2021 · 1 comment
Closed

Comments

@languitar
Copy link
Contributor

languitar commented May 10, 2021

This issue is created after the discussions in #390 (comment)

The existing argument exp_sig for executors assumes full POSIX compliance of the called executable, because the expected return code is assumed to be the negation of the signal code. This assumes a cooperating executable being called that follows the convention of negating the received signal. In my case, I am running a Click executable with SimpleExecutor. Click, by default, always returns 1 on unhandled signals and in this case also the returncode is then 1. This can easily be verified with:

executed.py:

import time

import click


@click.command()
def hello():
    while True:
        time.sleep(10)


if __name__ == "__main__":
    hello()

executor.py:

from pathlib import Path
import subprocess
import sys
import time
import signal


proc = subprocess.Popen([sys.executable, Path(__file__).parent / "executed.py"])
with proc:
    time.sleep(2)
    print(f"sending {signal.SIGINT}")
    proc.send_signal(signal.SIGINT)

print(f"Returncode: {proc.returncode}")
❯ python executor.py 
sending 2

Aborted!
Returncode: 1

This is unfortunate because now I have to specify exp_sig=-1 to avoid the process execution exception, but the statement conveys a different meaning than what is actually done now.

I would propose to drop this argument (or to provide a second one for backwards-compatibility) that is called expected_returncode(s). This argument wouldn't do any negation magic. Something like SimpleExecutor("prog", expected_returncode=1) is also pretty easy to understand.

@fizyk
Copy link
Member

fizyk commented May 12, 2021

I need to put that in my mind what I think I'll do:
We'll drop exp_sig alltogether.

If someone passes expected_returncode, we'll check for that, otherwise we'll attempt to guess it assuming POSIX compatibility. This will also benefit windows builds/attempts, I think 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants