forked from encode/uvicorn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override default asyncio event loop with reload only on Windows (enco…
…de#1257) * Override default asyncio loop with reload only * shortened warning * Added type hints for keyword arguments * Changed to explicit reload keyword argument for loop setups
- Loading branch information
Showing
4 changed files
with
11 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import asyncio | ||
import logging | ||
import sys | ||
|
||
logger = logging.getLogger("uvicorn.error") | ||
|
||
def asyncio_setup() -> None: # pragma: no cover | ||
if sys.version_info >= (3, 8) and sys.platform == "win32": | ||
|
||
def asyncio_setup(reload: bool = False) -> None: # pragma: no cover | ||
if sys.version_info >= (3, 8) and sys.platform == "win32" and reload: | ||
logger.warning("The --reload flag should not be used in production on Windows.") | ||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
def auto_loop_setup() -> None: | ||
def auto_loop_setup(reload: bool = False) -> None: | ||
try: | ||
import uvloop # noqa | ||
except ImportError: # pragma: no cover | ||
from uvicorn.loops.asyncio import asyncio_setup as loop_setup | ||
|
||
loop_setup() | ||
loop_setup(reload=reload) | ||
else: # pragma: no cover | ||
from uvicorn.loops.uvloop import uvloop_setup | ||
|
||
uvloop_setup() | ||
uvloop_setup(reload=reload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters