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

Support Windows #491

Open
5 tasks
ewjoachim opened this issue Nov 19, 2021 · 4 comments
Open
5 tasks

Support Windows #491

ewjoachim opened this issue Nov 19, 2021 · 4 comments
Labels
Issue appropriate for: People up for a challenge 🤨 This issue probably will be challenging to tackle Issue contains: Exploration & Design decisions 🤯 We don't know how this will be implemented yet Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some Windows 🪟 This issue will require skills and/or testing capabilities under Windows Issue type: Feature ⭐️ Add a new feature that didn't exist before

Comments

@ewjoachim
Copy link
Member

  • Add windows tests in the CI
  • Check that signals work the same way
  • Check that envvars work the same way
  • Adjust documentation
  • Find a windows maintainer
@ewjoachim ewjoachim added Issue appropriate for: People up for a challenge 🤨 This issue probably will be challenging to tackle Issue contains: Exploration & Design decisions 🤯 We don't know how this will be implemented yet Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some Windows 🪟 This issue will require skills and/or testing capabilities under Windows Issue type: Feature ⭐️ Add a new feature that didn't exist before labels Nov 19, 2021
@ewjoachim
Copy link
Member Author

Ping @aleksandr-shtaub

@aleksandr-shtaub
Copy link
Contributor

aleksandr-shtaub commented Nov 22, 2021

I'll start from the easy ones.

Env vars

Works as expected.

CMD

rem Set value for a variable Name. Note: Should not contain any whitespaces around `=`.
> set Name=Value

rem Get value of variable `Name`.
> echo %Name%
Value

or

PowerShell

# Set value for a variable Name. Note: powershell have types, so use `""` for a string type.
> $Env:Name = "Value"  

# Get value of variable.
> echo $Env:Name
Value

Example

# test.py
import os
print(os.environ.get("Greeter"))
> $Env:Greeter = "Hello!"
> python -m test
Hello!

Paths

Unix: a/b/c
Win: a\\b\\c

Consider using Path.asPosix() instead of str(Path) when testing paths.

Signals

signal.SIGINT, signal.SIGTERM are supported (kind of) (1)

Subprocess

Different resolving of executable path (2)

We should use full paths or shell=True when we use subprocess.Popen().
Popen is in tests so there is nothing to worry about.

Popen.send_signal(signal.SIGINT) is not supported on win (3)

# subprocess.py
...
    def send_signal(self, sig):
        """Send a signal to the process."""
        # Don't signal a process that we know has already died.
        if self.returncode is not None:
            return
        if sig == signal.SIGTERM:
            self.terminate()
        elif sig == signal.CTRL_C_EVENT:
            os.kill(self.pid, signal.CTRL_C_EVENT)
        elif sig == signal.CTRL_BREAK_EVENT:
            os.kill(self.pid, signal.CTRL_BREAK_EVENT)
        else:
            raise ValueError("Unsupported signal: {}".format(sig))
...

Event Loop

add_signal_handler() and remove_signal_handler() aren't supported on win (4)

ProactorEventLoop and SelectorEventLoop (5,6,7,8)

We cant' use ProactorEventLoop because add_reader() and remove_reader() are used by aiopg.
Since Python 3.8 we need to change default policy explicitly like:

if os.platform == "win32":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Tests

Pytest-asyncio doesn't pickup policy stated in our code (9, 10)

We can rewrite fixture like this:

@pytest.fixture
def event_loop(request):
    """Rewrite event_loop fixture for pytest_asyncio."""
    if sys.platform == "win32":
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    loop = asyncio.get_event_loop_policy().new_event_loop()
    yield loop
    loop.close()

TBC (if I find something else)

@aleksandr-shtaub
Copy link
Contributor

Related:
#286
#444
#451

@ewjoachim
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue appropriate for: People up for a challenge 🤨 This issue probably will be challenging to tackle Issue contains: Exploration & Design decisions 🤯 We don't know how this will be implemented yet Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some Windows 🪟 This issue will require skills and/or testing capabilities under Windows Issue type: Feature ⭐️ Add a new feature that didn't exist before
Projects
None yet
Development

No branches or pull requests

2 participants