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

CTRL-C always results in an error #139

Closed
dhermes opened this issue Sep 20, 2018 · 4 comments · Fixed by #393
Closed

CTRL-C always results in an error #139

dhermes opened this issue Sep 20, 2018 · 4 comments · Fixed by #393

Comments

@dhermes
Copy link
Collaborator

dhermes commented Sep 20, 2018

If nox -s foo encounters a KeyboardInterrupt but the currently running script catches it and handles it gracefully, nox will still report a failure. For example:

$ nox -s app -r
nox > Running session app-3.7
nox > Re-using existing virtualenv at .../.nox/app-3-7.
nox > pip install --upgrade --requirement .../requirements/app.txt
nox > cd .../src
nox > python -m flask run
 * Serving Flask app "app.py" (lazy loading)
...
127.0.0.1 - - [20/Sep/2018 15:43:27] "GET /foo HTTP/1.1" 200 -
127.0.0.1 - - [20/Sep/2018 15:43:31] "GET /bar HTTP/1.1" 200 -
127.0.0.1 - - [20/Sep/2018 15:43:33] "GET /baz HTTP/1.1" 404 -
^Cnox > Interrupted...
nox > Session app-3.7 interrupted.
$ echo $?
130

However, if the same application runs outside of nox there is no error (i.e. flask exits gracefully):

$ cd src/
$ FLASK_APP=app.py ../.nox/app-3-7/bin/python -m flask run
 * Serving Flask app "app.py"
...
127.0.0.1 - - [20/Sep/2018 15:46:09] "GET /foo HTTP/1.1" 200 -
127.0.0.1 - - [20/Sep/2018 15:46:12] "GET /baz HTTP/1.1" 404 -
127.0.0.1 - - [20/Sep/2018 15:46:13] "GET /bar HTTP/1.1" 200 -
^C
$ echo $?
0
$ cd ..

What should the correct nox behavior be here?

@theacodes
Copy link
Collaborator

Nox doesn't pass the signal to the subprocess, it just kills it outright. Maybe we should fix that.

@pradyunsg
Copy link
Contributor

FWIW, I have a session that might be affected by this:

@nox.session
def run(session):
    session.install("pelican")

    cmd = [
        "python",
        "-m",
        "http.server",
        str(CONFIGURATION["dev_port"]),
        "-d",
        CONFIGURATION["output_path"],
    ]
    # NOTE: A bare Popen() results in a child being spawned.
    #       As of nox 2018.10.17, this child gets killed when the process ends.
    session.log(" ".join(cmd) + " (background)")
    subprocess.Popen(cmd)

    # -r means this process rebuilds until it receives a ^C or gets killed.
    session.run("pelican", "-r", "-d", "-s", CONFIGURATION["dev"], "src")

TBH, this is more of a generic automation thing that I'm using nox for than just testing but I think it's pretty awesome that nox is flexible enough to be able to do this. :)

@cjolowicz
Copy link
Collaborator

Just adding another use case here...

This behavior also appears to break pytest --pdb. For example, when debugging something like intermittent deadlocks, ^C terminates pytest instead of dropping you into pdb.

@theacodes
Copy link
Collaborator

This could resolved by modifying this code to pass an interrupt signal to the child process instead of just killing it outright. We should, however, make sure to have some reasonable timeout and kill the child process if it hangs.

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

Successfully merging a pull request may close this issue.

4 participants