Skip to content

Commit

Permalink
Warn user when reload and workers flag are used together (#1731)
Browse files Browse the repository at this point in the history
* Warn user when reload and workers flag are used together

* Add test
  • Loading branch information
Kludex committed Oct 31, 2022
1 parent 4634b7f commit 26cace2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/test_config.py
Expand Up @@ -557,3 +557,12 @@ def test_config_use_subprocess(reload, workers, expected):
config = Config(app=asgi_app, reload=reload, workers=workers)
config.load()
assert config.use_subprocess == expected


def test_warn_when_using_reload_and_workers(caplog: pytest.LogCaptureFixture) -> None:
Config(app=asgi_app, reload=True, workers=2)
assert len(caplog.records) == 1
assert (
'"workers" flag is ignored when reloading is enabled.'
in caplog.records[0].message
)
3 changes: 3 additions & 0 deletions uvicorn/config.py
Expand Up @@ -372,6 +372,9 @@ def __init__(
else:
self.forwarded_allow_ips = forwarded_allow_ips

if self.reload and self.workers > 1:
logger.warning('"workers" flag is ignored when reloading is enabled.')

@property
def asgi_version(self) -> Literal["2.0", "3.0"]:
mapping: Dict[str, Literal["2.0", "3.0"]] = {
Expand Down

0 comments on commit 26cace2

Please sign in to comment.