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

Fix OSError: [WinError 87] The parameter is incorrect #1454

Merged
merged 8 commits into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/test_config.py
Expand Up @@ -544,3 +544,22 @@ def test_bind_fd_works_with_reload_or_workers(reload, workers): # pragma: py-wi
assert sock.getsockname() == ""
sock.close()
fdsock.close()


@pytest.mark.parametrize(
"reload, workers, expected",
[
(True, 1, True),
(False, 2, True),
(False, 1, False),
],
ids=[
"--reload=True --workers=1",
"--reload=False --workers=2",
"--reload=False --workers=1",
],
)
def test_config_use_subprocess(reload, workers, expected):
config = Config(app=asgi_app, reload=reload, workers=workers)
config.load()
assert config.use_subprocess == expected
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_process doesn't exist anymore on this branch. I was fine with it tho 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I reverted too much, goinmg to do that tomorrow sorry :_)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed up things etc... tired

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Have a good evening man! ♥️🙏

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok should be ok now @Kludex , apologies for the confusion :)

6 changes: 5 additions & 1 deletion uvicorn/config.py
Expand Up @@ -373,6 +373,10 @@ def asgi_version(self) -> Literal["2.0", "3.0"]:
def is_ssl(self) -> bool:
return bool(self.ssl_keyfile or self.ssl_certfile)

@property
def use_subprocess(self) -> bool:
return bool(self.reload or self.workers > 1)

def configure_logging(self) -> None:
logging.addLevelName(TRACE_LOG_LEVEL, "TRACE")

Expand Down Expand Up @@ -503,7 +507,7 @@ def load(self) -> None:
def setup_event_loop(self) -> None:
loop_setup: Optional[Callable] = import_from_string(LOOP_SETUPS[self.loop])
if loop_setup is not None:
loop_setup(reload=self.reload)
loop_setup(use_subprocess=self.use_subprocess)

def bind_socket(self) -> socket.socket:
logger_args: List[Union[str, int]]
Expand Down
5 changes: 2 additions & 3 deletions uvicorn/loops/asyncio.py
Expand Up @@ -5,7 +5,6 @@
logger = logging.getLogger("uvicorn.error")


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.")
def asyncio_setup(use_subprocess: bool = False) -> None: # pragma: no cover
if sys.version_info >= (3, 8) and sys.platform == "win32" and use_subprocess:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
6 changes: 3 additions & 3 deletions uvicorn/loops/auto.py
@@ -1,11 +1,11 @@
def auto_loop_setup(reload: bool = False) -> 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)
loop_setup(use_subprocess=use_subprocess)
else: # pragma: no cover
from uvicorn.loops.uvloop import uvloop_setup

uvloop_setup(reload=reload)
uvloop_setup(use_subprocess=use_subprocess)
2 changes: 1 addition & 1 deletion uvicorn/loops/uvloop.py
Expand Up @@ -3,5 +3,5 @@
import uvloop


def uvloop_setup(reload: bool = False) -> None:
def uvloop_setup(use_subprocess: bool = False) -> None:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())