From 8eb68a006e5ca252c6197d46e8b9026bb98c208d Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Tue, 31 Oct 2023 13:45:29 -0700 Subject: [PATCH] Expose gunicorn_worker_class via Config (#2084) --- reflex/config.py | 3 +++ reflex/config.pyi | 2 ++ reflex/utils/exec.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/reflex/config.py b/reflex/config.py index 9ab7dd57c..5f135f08e 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -198,6 +198,9 @@ class Config(Base): # The username. username: Optional[str] = None + # The worker class used in production mode + gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker" + # Attributes that were explicitly set by the user. _non_default_attributes: Set[str] = pydantic.PrivateAttr(set()) diff --git a/reflex/config.pyi b/reflex/config.pyi index ebe015ffd..0193d6533 100644 --- a/reflex/config.pyi +++ b/reflex/config.pyi @@ -69,6 +69,7 @@ class Config(Base): cp_backend_url: str cp_web_url: str username: Optional[str] + gunicorn_worker_class: str def __init__( self, @@ -95,6 +96,7 @@ class Config(Base): cp_backend_url: Optional[str] = None, cp_web_url: Optional[str] = None, username: Optional[str] = None, + gunicorn_worker_class: Optional[str] = None, **kwargs ) -> None: ... @staticmethod diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index f43234bfb..e63f1e718 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -185,7 +185,7 @@ def run_backend_prod( """ num_workers = processes.get_num_workers() config = get_config() - RUN_BACKEND_PROD = f"gunicorn --worker-class uvicorn.workers.UvicornH11Worker --preload --timeout {config.timeout} --log-level critical".split() + RUN_BACKEND_PROD = f"gunicorn --worker-class {config.gunicorn_worker_class} --preload --timeout {config.timeout} --log-level critical".split() RUN_BACKEND_PROD_WINDOWS = f"uvicorn --timeout-keep-alive {config.timeout}".split() app_module = f"{config.app_name}.{config.app_name}:{constants.CompileVars.APP}" command = (