From dddbeb0e7192f23371f1360150f1e9eedc302df5 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 25 Jul 2020 12:00:04 -0400 Subject: [PATCH] Run Windows on trio and mp backends The new pure trio spawning backend uses `subprocess` internally which is also supported on windows so let's run it in CI. --- .travis.yml | 22 ++++++++++++++++++++++ tests/conftest.py | 17 +++++++++-------- tests/test_cancellation.py | 4 +++- tractor/_spawn.py | 14 +++++++------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index d709871..d06332b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,17 @@ matrix: os: windows language: sh python: 3.x # only works on linux + env: SPAWN_BACKEND="mp" + before_install: + - choco install python3 --params "/InstallDir:C:\\Python" + - export PATH="/c/Python:/c/Python/Scripts:$PATH" + - python -m pip install --upgrade pip wheel + + - name: "Windows, Python Latest: trio" + os: windows + language: sh + python: 3.x # only works on linux + env: SPAWN_BACKEND="trio" before_install: - choco install python3 --params "/InstallDir:C:\\Python" - export PATH="/c/Python:/c/Python/Scripts:$PATH" @@ -16,6 +27,17 @@ matrix: - name: "Windows, Python 3.7: multiprocessing" os: windows python: 3.7 # only works on linux + env: SPAWN_BACKEND="mp" + language: sh + before_install: + - choco install python3 --version 3.7.4 --params "/InstallDir:C:\\Python" + - export PATH="/c/Python:/c/Python/Scripts:$PATH" + - python -m pip install --upgrade pip wheel + + - name: "Windows, Python 3.7: trio" + os: windows + python: 3.7 # only works on linux + env: SPAWN_BACKEND="trio" language: sh before_install: - choco install python3 --version 3.7.4 --params "/InstallDir:C:\\Python" diff --git a/tests/conftest.py b/tests/conftest.py index 64a072a..1ad2ded 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,13 +6,21 @@ import platform import pytest import tractor -from tractor.testing import tractor_test + +# export for tests +from tractor.testing import tractor_test # noqa pytest_plugins = ['pytester'] _arb_addr = '127.0.0.1', random.randint(1000, 9999) +no_windows = pytest.mark.skipif( + platform.system() == "Windows", + reason="Test is unsupported on windows", +) + + def pytest_addoption(parser): parser.addoption( "--ll", action="store", dest='loglevel', @@ -29,9 +37,6 @@ def pytest_addoption(parser): def pytest_configure(config): backend = config.option.spawn_backend - if platform.system() == "Windows": - backend = 'mp' - if backend == 'mp': tractor._spawn.try_set_start_method('spawn') elif backend == 'trio': @@ -68,10 +73,6 @@ def pytest_generate_tests(metafunc): # incompatible with trio's global scheduler state methods.remove('fork') elif spawn_backend == 'trio': - if platform.system() == "Windows": - pytest.fail( - "Only `--spawn-backend=mp` is supported on Windows") - methods = ['trio'] metafunc.parametrize("start_method", methods, scope='module') diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py index 0dbf2fe..5a471f7 100644 --- a/tests/test_cancellation.py +++ b/tests/test_cancellation.py @@ -10,7 +10,7 @@ import pytest import trio import tractor -from conftest import tractor_test +from conftest import tractor_test, no_windows async def assert_err(delay=0): @@ -339,6 +339,7 @@ async def test_nested_multierrors(loglevel, start_method): subexc.type is trio.Cancelled) +@no_windows def test_open_in_proc_cancel_via_SIGINT(loglevel, start_method): """Ensure that a control-C (SIGINT) signal cancels both the parent and child processes in trionic fashion @@ -356,6 +357,7 @@ def test_open_in_proc_cancel_via_SIGINT(loglevel, start_method): tractor.run(main) +@no_windows def test_open_in_proc_cancel_via_SIGINT_other_task( loglevel, start_method diff --git a/tractor/_spawn.py b/tractor/_spawn.py index b6b2e8d..5642083 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -55,12 +55,13 @@ else: def try_set_start_method(name: str) -> Optional[mp.context.BaseContext]: - """Attempt to set the start method for process starting, aka the "actor + """Attempt to set the method for process starting, aka the "actor spawning backend". - If the desired method is not supported this function will error. On - Windows the only supported option is the ``multiprocessing`` "spawn" - method. The default on *nix systems is ``trio``. + If the desired method is not supported this function will error. + On Windows only the ``multiprocessing`` "spawn" method is offered + besides the default ``trio`` which uses async wrapping around + ``subprocess.Popen``. """ global _ctx global _spawn_method @@ -70,9 +71,8 @@ def try_set_start_method(name: str) -> Optional[mp.context.BaseContext]: # forking is incompatible with ``trio``s global task tree methods.remove('fork') - # no Windows support for trip yet - if platform.system() != 'Windows': - methods += ['trio'] + # supported on all platforms + methods += ['trio'] if name not in methods: raise ValueError(