这是我的示例 Python 应用程序结构。我有这个应用程序在 Kubernetes 下运行,并有 Procfile 来检测和构建该应用程序并部署它。重新加载对于 Python 文件 (.py) 效果很好,而 .html 或 .css 文件等静态文件在更改时不会重新加载。
我可以看到更改文件已复制到容器中,但仅更改静态文件时,Gunicorn 不会重新启动工作线程,而在复制 Python (.py) 文件时会重新启动。我已经尝试了一天,但不确定在哪里寻找任何帮助会有很大帮助。
.
├── Procfile
├── README.md
├── Tiltfile
├── board
│ ├── __init__.py
│ ├── pages.py
│ ├── postgresql.py
│ ├── posts.py
│ ├── schema-postgres.sql
│ ├── static
│ └── templates
├── gunicorn_config.py
├── requirements.txt
├── venv
│ ├── bin
│ ├── include
│ ├── lib
│ └── pyvenv.cfg
└── wsgi.py
gunicorn_config.py
workers = 1
loglevel = 'info'
reload = True
reload_extra_file = ['/workspace/board/templates/*.html', '/workspace/board/static/*.css']
errorlog = '-'
accesslog = '-'
threads = 2
worker_class = 'gthread'
wsgi.py
from board import create_app
app = create_app()
if __name__ == '__main__':
app.run()
过程文件
web: gunicorn -b :8080 wsgi:app --config gunicorn_config.py
所有文件都复制到容器中的
/workspace
文件夹,如上所述,包括 .html 和 .css 更改在内的每个更改都会得到反映,但该过程不会重新加载/重新启动。
谢谢大家的帮助。我让它运行起来了。典型的是,我在配置中犯了一个拼写错误,它是
reload_extra_files
而不是 reload_extra_file
。其中一些值在命令行中使用时与在 Python 文件中使用时是不同的。
gunicorn_config.py(工作)
from glob import glob
workers = 1
loglevel = 'info'
reload = True
reload_extra_files = glob('board/**/*.html', recursive=True) + glob('board/**/*.css', recursive=True)
errorlog = '-'
accesslog = '-'