Systemd启动重复的python进程 [英] Systemd launches duplicate python processes

查看:90
本文介绍了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应用会创建两个进程?

这篇关于Systemd启动重复的python进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆