Systemd launches duplicate python processes

∥☆過路亽.° 提交于 2021-01-02 03:03:27

问题


I am using systemd to start a python flask app on raspberry pi zero(Raspbian buster).

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.

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

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)

回答1:


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)

More info here: Why does a Flask app create two process?



来源:https://stackoverflow.com/questions/61630798/systemd-launches-duplicate-python-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!