reflex-process-management
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReflex 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 --dryThis 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.logThis 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 captures both stdout and stderr to while still printing to the terminal.
2>&1 | tee reflex.logreflex.logImportant: Always useunless the user explicitly requests development mode.--env prod
当需要运行Reflex服务器时,请始终使用生产模式并将输出重定向到日志文件:
bash
reflex run --env prod --single-port 2>&1 | tee reflex.log该命令启动一个长期运行的服务器进程,生产模式不支持热重载。代码变更不会自动生效——必须停止并重启服务器才能应用变更(请参阅下方的重新加载运行中的应用)。
使用可将标准输出和标准错误同时捕获到中,同时仍在终端打印输出。
2>&1 | tee reflex.logreflex.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 to find the port the app is listening on. Look for a line like . Do not assume the port is 8000.
reflex.logApp running at: http://0.0.0.0:<port>读取以查找应用正在监听的端口。查找类似的行。不要假设端口是8000。
reflex.logApp running at: http://0.0.0.0:<port>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 -tThe 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.
-sTCP:LISTENIf is not available, use:
lsofbash
ss -tlnp | grep :<port>Or:
bash
fuser <port>/tcp使用步骤1中的端口,定位监听进程(而非浏览器连接):
bash
lsof -i :<port> -sTCP:LISTEN -t-sTCP:LISTEN如果不可用,请使用:
lsofbash
ss -tlnp | grep :<port>或:
bash
fuser <port>/tcpStep 3: Send an interrupt signal
步骤3:发送中断信号
Send (equivalent to Ctrl+C) to gracefully stop the process:
SIGINTbash
kill -INT $(lsof -i :<port> -sTCP:LISTEN -t)If the process doesn't stop, escalate to :
SIGTERMbash
kill -TERM $(lsof -i :<port> -sTCP:LISTEN -t)发送(等同于Ctrl+C)以优雅停止进程:
SIGINTbash
kill -INT $(lsof -i :<port> -sTCP:LISTEN -t)如果进程未停止,升级为:
SIGTERMbash
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.logInvestigating Errors
错误排查
When the user reports an error, read to find and diagnose the issue.
reflex.log当用户报告错误时,读取以查找并诊断问题。
reflex.log