reflex-process-management

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Reflex Process Management

Reflex进程管理

This skill covers how to compile, run, and reload a Reflex application.
本技能涵盖如何编译、运行和重新加载Reflex应用。

Compiling (Testing the App)

编译(测试应用)

To verify the app compiles without errors, run:
bash
reflex compile --dry
This checks for syntax errors, import issues, and component problems without starting the server. Use this as a quick validation step after making changes.
要验证应用编译无错误,运行:
bash
reflex compile --dry
此命令检查语法错误、导入问题和组件问题,无需启动服务器。在修改代码后,可将其作为快速验证步骤。

Running the Server

运行服务器

When instructed to run the Reflex server, always use production mode and redirect output to a log file:
bash
reflex run --env prod --single-port 2>&1 | tee reflex.log
This command starts a long-running server process that does not support hot reload in production mode. Code changes will not be picked up automatically — you must stop and restart the server to apply changes (see Reloading a Running App below).
Using
2>&1 | tee reflex.log
captures both stdout and stderr to
reflex.log
while still printing to the terminal.
Important: Always use
--env prod
unless the user explicitly requests development mode.
当需要运行Reflex服务器时,请始终使用生产模式并将输出重定向到日志文件:
bash
reflex run --env prod --single-port 2>&1 | tee reflex.log
该命令启动一个长期运行的服务器进程,生产模式不支持热重载。代码变更不会自动生效——必须停止并重启服务器才能应用变更(请参阅下方的重新加载运行中的应用)。
使用
2>&1 | tee reflex.log
可将标准输出和标准错误同时捕获到
reflex.log
中,同时仍在终端打印输出。
重要提示: 除非用户明确要求开发模式,否则请始终使用
--env prod
。

Reloading a Running App

重新加载运行中的应用

To reload the app without manually stopping and restarting from the terminal, follow these steps:
无需手动从终端停止并重启即可重新加载应用,请遵循以下步骤:

Step 1: Determine the app port

步骤1:确定应用端口

Read
reflex.log
to find the port the app is listening on. Look for a line like
App running at: http://0.0.0.0:<port>
. Do not assume the port is 8000.
读取
reflex.log
以查找应用正在监听的端口。查找类似
App running at: http://0.0.0.0:<port>
的行。不要假设端口是8000。

Step 2: Find the app process

步骤2:查找应用进程

Using the port from Step 1, locate the listening process (not browser connections):
bash
lsof -i :<port> -sTCP:LISTEN -t
The
-sTCP:LISTEN
flag is critical — it filters to only the server process that is listening on the port, excluding browser or client connections. Without it, you may kill the user's browser.
If
lsof
is not available, use:
bash
ss -tlnp | grep :<port>
Or:
bash
fuser <port>/tcp
使用步骤1中的端口,定位监听进程(而非浏览器连接):
bash
lsof -i :<port> -sTCP:LISTEN -t
-sTCP:LISTEN
标志至关重要——它仅过滤在该端口上监听的服务器进程,排除浏览器或客户端连接。如果没有此标志,可能会误杀用户的浏览器进程。
如果
lsof
不可用,请使用:
bash
ss -tlnp | grep :<port>
或:
bash
fuser <port>/tcp

Step 3: Send an interrupt signal

步骤3:发送中断信号

Send
SIGINT
(equivalent to Ctrl+C) to gracefully stop the process:
bash
kill -INT $(lsof -i :<port> -sTCP:LISTEN -t)
If the process doesn't stop, escalate to
SIGTERM
:
bash
kill -TERM $(lsof -i :<port> -sTCP:LISTEN -t)
发送
SIGINT
(等同于Ctrl+C)以优雅停止进程:
bash
kill -INT $(lsof -i :<port> -sTCP:LISTEN -t)
如果进程未停止,升级为
SIGTERM
:
bash
kill -TERM $(lsof -i :<port> -sTCP:LISTEN -t)

Step 4: Restart the server

步骤4:重启服务器

Once the old process has exited, truncate the old log and start the server again:
bash
> reflex.log
reflex run --env prod --single-port 2>&1 | tee reflex.log
旧进程退出后,清空旧日志并重新启动服务器:
bash
> reflex.log
reflex run --env prod --single-port 2>&1 | tee reflex.log

Investigating Errors

错误排查

When the user reports an error, read
reflex.log
to find and diagnose the issue.
当用户报告错误时,读取
reflex.log
以查找并诊断问题。