【发布时间】:2021-07-06 02:22:50
【问题描述】:
我有一个在 apache2 mod_wsgi 上运行的小型烧瓶应用程序,该应用程序有一个 Web 界面和一个应该在服务器上运行 h24 的单独线程。 问题是,当我连接到 Web 界面并且 Web 服务器正在为页面提供服务时,循环运行完美,如果我关闭浏览器,任务会停止,因为 apache 在 Flask 应用程序内停止任务,当我再次浏览它时重新启动备份。 是否有 apache2 设置或代码解决方法来解决这个问题?
<VirtualHost *:80>
ServerName 192.168.123.108
WSGIDaemonProcess app user=pi group=pi threads=5 display-name=%{GROUP} home=/var/www/fbot
WSGIScriptAlias /fbot /var/www/fbot/app.wsgi
WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/fbot/>
Options FollowSymLinks
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
app = Flask(__name__)
e = Engine(testing=True)
class Engine(Thread):
def __init__(self, testing):
self.exch = Ex(testing=testing)
thread = Thread(target=self.run, args=(testing, ))
thread.daemon = True
thread.start()
def run(self, testing):
# loop
while True:
#do things
time.sleep(60)
【问题讨论】:
标签: python flask apache2 mod-wsgi