MCPcopy
hub / github.com/reflex-dev/reflex / _run_dev

Function _run_dev

reflex/reflex.py:170–224  ·  view source on GitHub ↗

Run the app in development mode.

(
    running_mode: constants.RunningMode,
    frontend_port: int | None,
    backend_port: int | None,
    backend_host: str,
)

Source from the content-addressed store, hash-verified

168
169
170def _run_dev(
171 running_mode: constants.RunningMode,
172 frontend_port: int | None,
173 backend_port: int | None,
174 backend_host: str,
175):
176 """Run the app in development mode."""
177 import atexit
178
179 from reflex.utils import build, exec, processes, telemetry
180
181 config = get_config()
182
183 if frontend_port:
184 config._set_persistent(frontend_port=frontend_port)
185 if backend_port:
186 config._set_persistent(backend_port=backend_port)
187
188 if running_mode.has_frontend():
189 _compile_app()
190
191 # Post a telemetry event.
192 telemetry.send("run-dev")
193
194 # Display custom message when there is a keyboard interrupt.
195 atexit.register(processes.atexit_handler)
196
197 # Run the frontend and backend together.
198 commands = []
199
200 # Run the frontend on a separate thread.
201 if running_mode.has_frontend():
202 build.setup_frontend(Path.cwd())
203 commands.append((
204 exec.run_frontend,
205 Path.cwd(),
206 frontend_port,
207 running_mode.has_backend(),
208 ))
209
210 # Start the frontend and backend.
211 with processes.run_concurrently_context(*commands):
212 # In dev mode, run the backend on the main thread.
213 if running_mode.has_backend() and backend_port:
214 exec.run_backend(
215 backend_host,
216 int(backend_port),
217 config.loglevel.subprocess_level(),
218 running_mode.has_frontend(),
219 )
220 # The windows uvicorn bug workaround
221 # https://github.com/reflex-dev/reflex/issues/2335
222 if constants.IS_WINDOWS and exec.frontend_process:
223 # Sends SIGTERM in windows
224 exec.kill(exec.frontend_process.pid)
225
226
227def _run_prod(running_mode: constants.RunningMode, port: int, host: str):

Callers 1

_runFunction · 0.85

Calls 7

get_configFunction · 0.90
_set_persistentMethod · 0.80
has_frontendMethod · 0.80
registerMethod · 0.80
has_backendMethod · 0.80
subprocess_levelMethod · 0.80
_compile_appFunction · 0.70

Tested by

no test coverage detected