Systemd启动重复的python进程
我正在使用systemd在树莓派零(Raspbian buster)上启动python flask应用程序.
I am using systemd to start a python flask app on raspberry pi zero(Raspbian buster).
每次启动服务时,它都会启动两个python进程,而不是一个.为什么会这样?
Every time I start a service, it launches two python processes instead of one. Why does this happen?
第一个进程是第二个进程的父级.
The first process is the parent of the second process.
这是我在/etc/systemd/system/website.service中的服务定义:
Here is my service definition in /etc/systemd/system/website.service:
[Unit]
Description=Website
After=network.target
[Service]
User=root
WorkingDirectory=/home/pi/dev
ExecStart=python /home/pi/dev/app.py
Restart=always
[Install]
WantedBy=multi-user.target
这是/home/pi/dev/app.py
Here is the flask app in /home/pi/dev/app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
我找到了答案,Flask的dev服务器正在与重新加载器一起运行,因此它正在启动两个进程.如果在启动Flask应用程序时添加 use_reloader = False
,它将仅启动一个进程.
I found the answer, Flask's dev server is running with the reloader so it's launching two processes. If I add use_reloader=False
when starting the Flask app, it will only start one process.
app.run(host='0.0.0.0', debug=True, use_reloader=False)
此处的更多信息:为什么Flask应用会创建两个进程?