Heim  >  Fragen und Antworten  >  Hauptteil

python - flask + gunicorn数据查询问题

flask + gunicorn运行程序,在数据库中手动insert数据后,需要重启gunicorn,flask程序才能查到新数据。

PHP中文网PHP中文网2741 Tage vor308

Antworte allen(2)Ich werde antworten

  • PHPz

    PHPz2017-04-18 09:55:10

    你需要在请求前后或者请求后断开数据库连接

    @app.teardown_request
    def shutdown_session(exception=None):
        app.logger.debug('remove session')
        db_session.remove()

    Antwort
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:55:10

    这个问题应该不是gunicorn重启不重启的问题。应该是缓存问题。数据库的数据改变了,但是flask在内存中依然存的是以前的数据,你没有重新去载入数据导致的吧。不知道你具体怎么用的。只能说这么多了。

    Antwort
    0
  • StornierenAntwort