Skip to content

Commit

Permalink
Run Windows on trio and mp backends
Browse files Browse the repository at this point in the history
The new pure trio spawning backend uses `subprocess` internally which is
also supported on windows so let's run it in CI.
  • Loading branch information
goodboy committed Jul 25, 2020
1 parent 7c3928f commit dddbeb0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
17 changes: 9 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

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',
Expand All @@ -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':
Expand Down Expand Up @@ -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')
4 changes: 3 additions & 1 deletion tests/test_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import trio
import tractor

from conftest import tractor_test
from conftest import tractor_test, no_windows


async def assert_err(delay=0):
Expand Down Expand Up @@ -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
Expand All @@ -356,6 +357,7 @@ async def main():
tractor.run(main)


@no_windows
def test_open_in_proc_cancel_via_SIGINT_other_task(
loglevel,
start_method
Expand Down
14 changes: 7 additions & 7 deletions tractor/_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ async def proc_waiter(proc: mp.Process) -> None:


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
Expand All @@ -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(
Expand Down

0 comments on commit dddbeb0

Please sign in to comment.