无限星辰工作室-客户无限互联网动力之源

标题: pyinstaller打包gunicorn启动的Flask [打印本页]

作者: crx349    时间: 2024-7-14 18:43
标题: pyinstaller打包gunicorn启动的Flask
app.py
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from hello import hallo
  4. from flask import Flask
  5. app = Flask(__name__)

  6. @app.route('/')
  7. def hello():
  8.     return 'hello world'


  9. application = app

  10. #以gunicorn 启动的Flask不会走main方法所以下面的可以注释掉

  11. if __name__=="__main__":
  12.     app.run()
复制代码


gunicorn.py
  1. #!/usr/bin/env python3

  2. from gunicorn.app.base import BaseApplication

  3. class Application(BaseApplication):
  4.     def load_config(self):
  5.         s = self.cfg.set
  6.         s('bind', "0.0.0.0:18000")
  7.         s('workers', 1)
  8.         s('timeout', 30)
  9.         s('accesslog', "/opt/xmspace/log/gunicorn_access.log")
  10.         s('errorlog', "/opt/xmspace/log/gunicorn_error.log")
  11.         s('access_log_format', '%(t)s %(h)s "%(r)s" %(s)s %(b)s %(D)s "%(a)s"')

  12.     def load(self):
  13.         from app import application
  14.         return application

  15. if __name__ == '__main__':
  16.     Application().run()
复制代码


ssh下执行
  1. pyinstaller -F gunicorn.py --name gun  --hidden-import gunicorn.glogging --hidden-import gunicorn.workers.sync
复制代码


flask默认启动是单线程 gunicorn启动好处就是多线程多并发





欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://xmspace.net/) Powered by Discuz! X3.4