【发布时间】:2015-11-15 22:54:21
【问题描述】:
我有一个使用 gunicorn 和 nginx 运行的 Flask 应用程序。但是,如果我更改数据库中的值,应用程序在某些情况下无法在浏览器中更新。
我有一个包含以下命令的烧瓶脚本
from msldata import app, db, models
path = os.path.dirname(os.path.abspath(__file__))
manager = Manager(app)
@manager.command
def run_dev():
app.debug = True
if os.environ.get('PROFILE'):
from werkzeug.contrib.profiler import ProfilerMiddleware
app.config['PROFILE'] = True
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
if 'LISTEN_PORT' in app.config:
port = app.config['LISTEN_PORT']
else:
port = 5000
print app.config
app.run('0.0.0.0', port=port)
print app.config
@manager.command
def run_server():
from gunicorn.app.base import Application
from gunicorn.six import iteritems
# workers = multiprocessing.cpu_count() * 2 + 1
workers = 1
options = {
'bind': '0.0.0.0:5000',
}
class GunicornRunner(Application):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super(GunicornRunner, self).__init__()
def load_config(self):
config = dict([(key, value) for key, value in iteritems(self.options) if key in self.cfg.settings and value is not None])
for key, value in iteritems(config):
self.cfg.set(key.lower(), value)
def load(self):
return self.application
GunicornRunner(app, options).run()
- 现在,如果我在调试模式下运行服务器
run_dev,则数据库修改会更新 - 如果使用
run_server,除非重新启动应用程序,否则不会看到修改 - 但是,如果我像
gunicorn -c a.py app:app一样运行,则数据库更新是可见的。
a.py 内容
import multiprocessing
bind = "0.0.0.0:5000"
workers = multiprocessing.cpu_count() * 2 + 1
关于我缺少什么的任何建议..
【问题讨论】:
-
db modifications是如何更新的?是否显示在网页上? -
Sequelpro 应用程序
-
更改为
config['CACHE_TYPE'] = 'FileSystemCache'并设置目录。喜欢bellow
标签: python nginx flask gunicorn mod-wsgi