Skip to content

Add Winloop To the list of loop setups and optional-dependencies #2558

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ standard = [
"python-dotenv>=0.13",
"PyYAML>=5.1",
"uvloop>=0.14.0,!=0.15.0,!=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and platform_python_implementation != 'PyPy')",
"winloop>=0.1.7; sys_platform == 'win32' or (sys_platform == 'cygwin' and platform_python_implementation != 'PyPy')",
"watchfiles>=0.13",
"websockets>=10.4",
]
4 changes: 3 additions & 1 deletion uvicorn/config.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
HTTPProtocolType = Literal["auto", "h11", "httptools"]
WSProtocolType = Literal["auto", "none", "websockets", "wsproto"]
LifespanType = Literal["auto", "on", "off"]
LoopSetupType = Literal["none", "auto", "asyncio", "uvloop"]
LoopSetupType = Literal["none", "auto", "asyncio", "uvloop", "winloop"]
InterfaceType = Literal["auto", "asgi3", "asgi2", "wsgi"]

LOG_LEVELS: dict[str, int] = {
@@ -59,7 +59,9 @@
"auto": "uvicorn.loops.auto:auto_loop_setup",
"asyncio": "uvicorn.loops.asyncio:asyncio_setup",
"uvloop": "uvicorn.loops.uvloop:uvloop_setup",
"winloop": "uvicorn.loops.winloop:winloop_setup",
}

INTERFACES: list[InterfaceType] = ["auto", "asgi3", "asgi2", "wsgi"]

SSL_PROTOCOL_VERSION: int = ssl.PROTOCOL_TLS_SERVER
13 changes: 10 additions & 3 deletions uvicorn/loops/auto.py
Original file line number Diff line number Diff line change
@@ -2,10 +2,17 @@ def auto_loop_setup(use_subprocess: bool = False) -> None:
try:
import uvloop # noqa
except ImportError: # pragma: no cover
from uvicorn.loops.asyncio import asyncio_setup as loop_setup
try:
import winloop # noqa
except ImportError:
from uvicorn.loops.asyncio import asyncio_setup as loop_setup

loop_setup(use_subprocess=use_subprocess)
loop_setup(use_subprocess=use_subprocess)
else:
from uvicorn.loops.winloop import winloop_setup as loop_setup

loop_setup(use_subprocess=use_subprocess)
else: # pragma: no cover
from uvicorn.loops.uvloop import uvloop_setup

uvloop_setup(use_subprocess=use_subprocess)

7 changes: 7 additions & 0 deletions uvicorn/loops/winloop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import asyncio

import winloop


def winloop_setup(use_subprocess: bool = False) -> None:
asyncio.set_event_loop_policy(winloop.EventLoopPolicy())