Skip to content

Commit 898c446

Browse files
authored
fix gunicorn in prod mode (#5521)
* fix gunicorn in prod mode * change fix
1 parent 9ffa3cb commit 898c446

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

reflex/utils/exec.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,37 @@ def run_uvicorn_backend_prod(host: str, port: int, loglevel: LogLevel):
573573
port: The app port
574574
loglevel: The log level.
575575
"""
576+
import os
577+
import shlex
578+
576579
from reflex.utils import processes
577580

578581
app_module = get_app_instance()
579582

580-
command = (
581-
["uvicorn", *("--host", host), *("--port", str(port)), "--factory", app_module]
582-
if constants.IS_WINDOWS
583-
else ["gunicorn", "--preload", *("--bind", f"{host}:{port}"), f"{app_module}()"]
584-
)
583+
if constants.IS_WINDOWS:
584+
command = [
585+
"uvicorn",
586+
*("--host", host),
587+
*("--port", str(port)),
588+
"--factory",
589+
app_module,
590+
]
591+
else:
592+
# Parse GUNICORN_CMD_ARGS for user overrides
593+
env_args = []
594+
if gunicorn_cmd_args := os.environ.get("GUNICORN_CMD_ARGS", ""):
595+
env_args = shlex.split(gunicorn_cmd_args)
596+
597+
# Our default args, then env args (env args win on conflicts)
598+
command = [
599+
"gunicorn",
600+
"--preload",
601+
"--worker-class",
602+
"uvicorn.workers.UvicornH11Worker",
603+
*("--bind", f"{host}:{port}"),
604+
*env_args,
605+
f"{app_module}()",
606+
]
585607

586608
command += [
587609
*("--log-level", loglevel.value),

0 commit comments

Comments
 (0)