Skip to content

Commit 72a5570

Browse files
committed
add strict hot reload env flag to detect envvars on hotreload (#5311)
1 parent 710da3c commit 72a5570

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

reflex/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@ class EnvironmentVariables:
748748
# The timeout to wait for a pong from the websocket server in seconds.
749749
REFLEX_SOCKET_TIMEOUT: EnvVar[int] = env_var(constants.Ping.TIMEOUT)
750750

751+
# Whether to run Granian in a spawn process. This enables Reflex to pick up on environment variable changes between hot reloads.
752+
REFLEX_STRICT_HOT_RELOAD: EnvVar[bool] = env_var(False)
753+
751754

752755
environment = EnvironmentVariables()
753756

reflex/utils/exec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ def run_granian_backend(host: str, port: int, loglevel: LogLevel):
384384
"""
385385
console.debug("Using Granian for backend")
386386

387+
if environment.REFLEX_STRICT_HOT_RELOAD.get():
388+
import multiprocessing
389+
390+
multiprocessing.set_start_method("spawn", force=True)
391+
387392
from granian.constants import Interfaces
388393
from granian.log import LogLevels
389394
from granian.server import MPServer as Granian

0 commit comments

Comments
 (0)