Reputation: 126
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)
Upvotes: 0
Views: 648
Reputation: 126
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?
Upvotes: 3