python - Apache HTTP Server 和 Flask:避免在一段时间后重新启动 Python 应用程序
问题描述
我有一个使用 Apache HTTP Server 运行的烧瓶服务器。python 程序首先将大量文件加载到内存中(大约需要 10 分钟),然后提供一些 REST API。
在一段时间内一切正常,但在一天左右(或一些不活动?)之后,python 程序关闭。当有新请求进来时,程序会重新启动(所以一段时间后的第一个请求需要 10 分钟)。python程序中创建的缓存自然也是空的。
这是我的/etc/apache2/sites-available/server.conf
(我用尖括号替换了我的实际路径):
<VirtualHost *:80>
# Add machine's IP address (use ifconfig command)
ServerName <IP here>
WSGIDaemonProcess myapp python-home=<path>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
# Give an alias to to start your website url with
WSGIScriptAlias <some alias> <path to wsgi>
<Directory <dir>>
# set permissions as per apache2.conf file
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog
</VirtualHost>
这是我在以下位置找到的 wsgi 文件<path to wsgi>
:
#! /usr/bin/python3111
import logging
import sys
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '<python application root>')
from flask_server import app as application
application.secret_key = 'anything you wish'
我想我错过了一些让 python 程序永远活着的配置行......?
解决方案
推荐阅读
- python - 将 Matlab 转换为 Python,重新缩放的问题
- asp.net-core - 在多层 .net 核心项目中使用全球化和本地化
- python - 如何检测 Created Exe 创建的另一个 exe 是否关闭?
- javascript - How to not to resize the content while using drawer in Material UI
- python - 如何使 tkinter 按钮附加或替换标签中的文本
- python - Can we return 2 inner functions from 1 outer functions?
- javascript - 带有保存按钮的可编辑 HTML 表单
- swift - 包含视图的动态结构数组
- angular - 不同组件中的角度路线导航
- json - 创建单个对象时,对象会两次存储到 django 数据库中。如何解决这种意外行为?