gunicorn


參考連接 http://docs.gunicorn.org/en/latest/install.html

https://blog.csdn.net/dutsoft/article/details/51452598

安裝 pip install gunicorn 

基於 json tex2 板子 pip 版本對gunicorn 安裝支持不穩定 特別是gunicron 19.0.3 版本之上的

 這里可以用sudo apt-get install gunicorn 安裝穩定版本

對於啟動項目可能會出現的 bug 

gunicorn 會加載虛擬環境之外 也就是說 在虛擬環境中會加載虛擬環境之外的安裝位置 這里不會拋出 關於gunicorn 的錯誤

基本的解決思路 先檢查你的安裝位置  退出虛擬環境 卸載gunicorn (如果使用pip管理)

$ deactivate

sudo pip uninstall gunicorn

再次進入虛擬環境:
$ pyenv activate
(env) $ pip install gunicorn

關於gunicorn 的啟動方式

指定為gevent 這個地方需要在項目禁止線程的使用,具體原因我也沒找到, 可能與我的項目其他配置有關系

gunicorn -k gevent -b 127.0.0.1:5000 manage:app

指定進程啟動

gunicorn -w 2 -b 127.0.0.1:5000 manage:app

最常用的是配置寫入文件進行啟動 

gunicorn -c gunicorn.conf manage:app

配置文件

import os
import gevent.monkey
gevent.monkey.patch_all()

import multiprocessing

debug = True
loglevel = 'debug'
bind = '0.0.0.0:8800'
pidfile = 'log/gunicorn.pid'
logfile = 'log/debug.log'

#啟動的進程數
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gunicorn.workers.ggevent.GeventWorker'

x_forwarded_for_header = ''

 

查看進程 pstree -ap | grep gunicorn

用gevent 啟動項目 一定要注意配置日志文件 后台無法打印 debug 調試

關閉gunicorn 可以用kill 直接將主進程殺死

 對於gunicorn 進程的管理  建議使用 supervisor

Supervisor是用Python開發的一個client/server服務,是Linux/Unix系統下的一個進程管理工具。它可以很方便的監聽、啟動、停止、重啟一個或多個進程

 Supervisor 是系統級別的 直接安裝到虛擬環境之外就可以,用Supervisor管理的進程,supervisort監聽到進程掛掉之后,會自動重啟, 也可禁止監聽。

Supervisor-守護進程工具


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM