Home  >  Q&A  >  body text

python - flask + gunicorn数据查询问题

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

PHP中文网PHP中文网2741 days ago309

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-18 09:55:10

    You need to disconnect the database before and after the request or after the request

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

    reply
    0
  • 天蓬老师

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

    This problem should not be a problem of gunicorn not restarting. It should be a cache issue. The data in the database has changed, but flask still stores the previous data in the memory. It may be caused by you not reloading the data. I don't know exactly how you use it. That's all I can say.

    reply
    0
  • Cancelreply