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

Restore CTRL-C handling by setting new flag in libmamba #340

Merged
merged 23 commits into from
Nov 2, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5976fc
call pthred_sigmask to restore CTRL-C handling
dholth Oct 28, 2023
0c50882
use upcoming use_default_signal_handler if available
jaimergp Oct 28, 2023
4a729a8
flip logic here for clarity
jaimergp Oct 28, 2023
42c1345
ensure new group and use BREAK instead
jaimergp Oct 30, 2023
37b346f
timeout here too, just in case
jaimergp Oct 30, 2023
b6eb8cc
that flag is only importable on win
jaimergp Oct 30, 2023
c9c5c3e
Merge branch 'main' into pthread-sigmask-ctrl-c
jaimergp Oct 30, 2023
955155d
try with ctrl-c again (but separate group)
jaimergp Oct 31, 2023
eb1e30e
Merge branch 'pthread-sigmask-ctrl-c' of github.com:dholth/conda-libm…
jaimergp Oct 31, 2023
be422a6
Update conda_libmamba_solver/mamba_utils.py
dholth Nov 1, 2023
ceb7951
Merge branch 'main' into pthread-sigmask-ctrl-c
jaimergp Nov 1, 2023
8210974
Merge branch 'main' into pthread-sigmask-ctrl-c
jezdez Nov 1, 2023
63c7e22
remove sigmask
jaimergp Nov 1, 2023
e391254
amend news
jaimergp Nov 1, 2023
395182b
Fix ctrlc tests on Windows.
jezdez Nov 1, 2023
fe9e8aa
Merge branch 'pthread-sigmask-ctrl-c' of https://github.com/dholth/co…
jezdez Nov 1, 2023
3df8fb4
Update tests/test_workarounds.py
dholth Nov 2, 2023
f84b9ed
Use a pytest finalizer for resetting the windows ctrl-c handler.
jezdez Nov 2, 2023
1346f16
No finalizer.
jezdez Nov 2, 2023
f5ce2e2
Fix import.
jezdez Nov 2, 2023
f455785
Rerun all failures.
jezdez Nov 2, 2023
585d8b9
Install pytest-rerunfailures
jezdez Nov 2, 2023
ca5e2c3
Fix for real.
jezdez Nov 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conda_libmamba_solver/mamba_utils.py
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ def set_channel_priorities(index: Dict[str, "_ChannelRepoInfo"], has_priority: b


def init_api_context() -> api.Context:
# This function has to be called BEFORE 1st initialization of the context
api.Context.use_default_signal_handler(False)
api_ctx = api.Context()

# Output params
19 changes: 19 additions & 0 deletions news/339-pthread-sigmask
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Do not use `libmamba`'s default signal handler so users can `Ctrl-C` from `conda`. (#337 via #340)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ addopts = [
"--strict-markers",
"--xdoctest-modules",
"--xdoctest-style=google",
"--reruns=3",
]

markers = [
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
conda-build
conda-forge::pytest-xprocess
conda-index
conda-build
conda-lock
# needed for many conda tests
flask
61 changes: 57 additions & 4 deletions tests/test_workarounds.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Copyright (C) 2022 Anaconda, Inc
# Copyright (C) 2023 conda
# SPDX-License-Identifier: BSD-3-Clause
import ctypes
import json
import signal
import subprocess as sp
import sys
from subprocess import PIPE, check_call, run
import time

import pytest
from conda.common.compat import on_win


def test_matchspec_star_version():
@@ -12,7 +18,7 @@ def test_matchspec_star_version():
We work around that with `.utils.safe_conda_build_form()`.
Reported in https://github.com/conda/conda/issues/11347
"""
check_call(
sp.check_call(
[
sys.executable,
"-m",
@@ -31,7 +37,7 @@ def test_matchspec_star_version():


def test_build_string_filters():
process = run(
process = sp.run(
[
sys.executable,
"-m",
@@ -44,7 +50,7 @@ def test_build_string_filters():
"numpy=*=*py38*",
"--json",
],
stdout=PIPE,
stdout=sp.PIPE,
text=True,
)
print(process.stdout)
@@ -56,3 +62,50 @@ def test_build_string_filters():
assert pkg["version"].startswith("3.8")
if pkg["name"] == "numpy":
assert "py38" in pkg["build_string"]


@pytest.mark.parametrize("stage", ["Collecting package metadata", "Solving environment"])
def test_ctrl_c(stage):
p = sp.Popen(
[
sys.executable,
"-m",
"conda",
"create",
"-p",
"UNUSED",
"--dry-run",
"--solver=libmamba",
"--override-channels",
"--channel=conda-forge",
"vaex",
],
text=True,
stdout=sp.PIPE,
stderr=sp.PIPE,
)
t0 = time.time()
while stage not in p.stdout.readline():
time.sleep(0.1)
if time.time() - t0 > 30:
raise RuntimeError("Timeout")

# works around Windows' awkward CTRL-C signal handling
# https://stackoverflow.com/a/64357453
if on_win:
try:
kernel = ctypes.windll.kernel32
kernel.FreeConsole()
kernel.AttachConsole(p.pid)
kernel.SetConsoleCtrlHandler(None, 1)
kernel.GenerateConsoleCtrlEvent(0, 0)
p.wait(timeout=30)
assert p.returncode != 0
assert "KeyboardInterrupt" in p.stdout.read() + p.stderr.read()
finally:
kernel.SetConsoleCtrlHandler(None, 0)
else:
p.send_signal(signal.SIGINT)
p.wait(timeout=30)
assert p.returncode != 0
assert "KeyboardInterrupt" in p.stdout.read() + p.stderr.read()