无限星辰工作室-客户无限互联网动力之源
标题:
pyinstaller打包gunicorn启动的Flask
[打印本页]
作者:
crx349
时间:
2024-7-14 18:43
标题:
pyinstaller打包gunicorn启动的Flask
app.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from hello import hallo
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'hello world'
application = app
#以gunicorn 启动的Flask不会走main方法所以下面的可以注释掉
if __name__=="__main__":
app.run()
复制代码
gunicorn.py
#!/usr/bin/env python3
from gunicorn.app.base import BaseApplication
class Application(BaseApplication):
def load_config(self):
s = self.cfg.set
s('bind', "0.0.0.0:18000")
s('workers', 1)
s('timeout', 30)
s('accesslog', "/opt/xmspace/log/gunicorn_access.log")
s('errorlog', "/opt/xmspace/log/gunicorn_error.log")
s('access_log_format', '%(t)s %(h)s "%(r)s" %(s)s %(b)s %(D)s "%(a)s"')
def load(self):
from app import application
return application
if __name__ == '__main__':
Application().run()
复制代码
ssh下执行
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