forked from encode/uvicorn
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added use_subprocess to be more generic
- Loading branch information
Showing
5 changed files
with
31 additions
and
26 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
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,21 +1,11 @@ | ||
import asyncio | ||
import logging | ||
import sys | ||
from typing import Optional | ||
|
||
logger = logging.getLogger("uvicorn.error") | ||
|
||
|
||
def asyncio_setup( | ||
reload: bool = False, workers: Optional[int] = None | ||
) -> None: # pragma: no cover | ||
if ( | ||
sys.version_info >= (3, 8) | ||
and sys.platform == "win32" | ||
and any([reload, workers]) | ||
): | ||
if reload: | ||
logger.warning( | ||
"The --reload flag should not be used in production on Windows." | ||
) | ||
def asyncio_setup(use_subprocess: bool = False) -> None: # pragma: no cover | ||
if sys.version_info >= (3, 8) and sys.platform == "win32" and use_subprocess: | ||
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,14 +1,11 @@ | ||
from typing import Optional | ||
|
||
|
||
def auto_loop_setup(reload: bool = False, workers: Optional[int] = None) -> None: | ||
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 | ||
|
||
loop_setup(reload=reload, workers=workers) | ||
loop_setup(use_subprocess=use_subprocess) | ||
else: # pragma: no cover | ||
from uvicorn.loops.uvloop import uvloop_setup | ||
|
||
uvloop_setup(reload=reload, workers=workers) | ||
uvloop_setup(use_subprocess=use_subprocess) |
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,8 +1,7 @@ | ||
import asyncio | ||
from typing import Optional | ||
|
||
import uvloop | ||
|
||
|
||
def uvloop_setup(reload: bool = False, workers: Optional[int] = None) -> None: | ||
def uvloop_setup(use_subprocess: bool = False) -> None: | ||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) |