说我有一个模块setup.py
,在server.py
中有一些烧瓶应用程序代码。
说我想运行gunicorn -b :$PORT server:app
。但是我想先在setup.py
中运行逻辑,然后再设置WSGI服务器并在server.py
中运行任何其他逻辑。
[似乎没有记录到任何用粗麻布制成的旗帜,让我来进行此操作(除非我丢失了某些东西)。基本上我想做类似gunicorn --RunThisFirst setup.py -b :$PORT server:app
使用gunicorn.conf.py
文件应该可以解决问题。
import multiprocessing
import os
###########
# INSERT / IMPORT setup code
#
# maybe like this...
#
# from src.setup import run_setup
#
# run_setup()
###########
port = os.getenv("PORT", 8000)
bind = f"127.0.0.1:{port}"
workers = multiprocessing.cpu_count() * 2 + 1
正在运行的服务器:
gunicorn --check-config server:app
在您独特的用例中,您可能需要将gunicorn
指向哪里(请参见docs):
gunicorn -c /path/to/gunicorn.config.py server:app
链接到与使用gunicorn.config.py
相关的文档:https://docs.gunicorn.org/en/latest/configure.html#configuration-file