Skip to content

Commit

Permalink
Suppress the usage of workers parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Dec 1, 2024
1 parent df66563 commit 9e95889
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pyninja/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def start(**kwargs) -> None:
rate_limit: List of dictionaries with ``max_requests`` and ``seconds`` to apply as rate limit.
log_config: Logging configuration as a dict or a FilePath. Supports .yaml/.yml, .json or .ini formats.
"""
# todo: Raise an issue with uvicorn or use a different server to host the API
# Problem:
# 1. Setting > 1 worker ignores all the routes since multiprocessing in python will ignore function calls
# 2. Unable to declare app within the 'start' function
# WARNING: You must pass the application as an import string to enable 'reload' or 'workers'.
# 3. Worker parameter is ignored when server is initiated from Config
# https://github.com/encode/uvicorn/discussions/2215
# 4. FastAPI ignores lifespan function since the app is already initiated and routes can't be added after startup
# 5. Overriding `uvicorn.Server` may be a solution but first figure out the above
models.env = squire.load_env(**kwargs)
squire.assert_tokens()
squire.assert_pyudisk()
Expand Down Expand Up @@ -198,7 +207,7 @@ def start(**kwargs) -> None:
kwargs = dict(
host=models.env.ninja_host,
port=models.env.ninja_port,
workers=models.env.workers,
# workers=models.env.workers,
app=f"{module_name.parent.stem}.{module_name.stem}:{PyNinjaAPI.__name__}",
)
if models.env.log_config:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pydantic-settings==2.*
python-multipart==0.0.*
PyYaml==6.0.*
requests==2.*
uvicorn[standard]==0.30.*
uvicorn[standard]==0.32.*

0 comments on commit 9e95889

Please sign in to comment.