touliu_app.py 592 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Quart
  5. from routes import Routes
  6. from applications import AsyncMySQLClient
  7. # init app
  8. app = Quart(__name__)
  9. asyncMysql = AsyncMySQLClient(app)
  10. appRoutes = Routes(asyncMysql)
  11. app.register_blueprint(appRoutes)
  12. @app.before_serving
  13. async def initDB():
  14. """
  15. init db pool before server is up
  16. :return:
  17. """
  18. await asyncMysql.initPool()
  19. @app.after_serving
  20. async def closeDB():
  21. """
  22. close db pool after server is down
  23. :return:
  24. """
  25. await asyncMysql.closePool()
  26. if __name__ == '__main__':
  27. app.run(debug=True)