如何使用 nodemon 在 Python 文件更改时自动重启 bottle 服务器

假设你有一个 Python 脚本 server.py,你想在每次文件更改时自动重新加载,使用以下 nodemon 脚本:

nodemon_start.sh
nodemon -w . --exec python server.py
nodemon_start.sh
nodemon -w . --exec python server.py

-w . 告诉 nodemon 监视当前目录(.)中所有文件的更改

我通常建议创建一个脚本 start.sh 来自动运行此命令:

start_nodemon.sh
#!/bin/sh
nodemon -w . --exec python server.py
start.sh
#!/bin/sh
nodemon -w . --exec python server.py

然后使用以下命令使其可执行

chmod_start.sh
chmod a+x start.sh
chmod_start.sh
chmod a+x start.sh

现在你可以使用以下命令运行它

run_start.sh
./start.sh
run_start.sh
./start.sh

Check out similar posts by category: Python