Python 安装 uWSGI并运行一个入门示例
生活随笔
收集整理的這篇文章主要介紹了
Python 安装 uWSGI并运行一个入门示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python 安裝 uWSGI
1、通過 pip 命令:
pip install uwsgi2、下載安裝腳本:
curl http://uwsgi.it/install | bash -s default /tmp/uwsgi將 uWSGI 二進制安裝到 /tmp/uwsgi ,你可以修改它。
3、源代碼安裝:
wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz tar zxvf uwsgi-latest.tar.gz cd uwsgi-latest make安裝完成后,在當前目錄下,你會獲得一個 uwsgi 二進制文件。
第一個 WSGI 應用
讓我們從一個簡單的 “Hello World” 開始,創建文件 foobar.py,代碼如下:
def application(env, start_response):start_response('200 OK', [('Content-Type','text/html')])return [b"Hello World"]uWSGI Python 加載器將會搜索的默認函數 application 。
接下來我們啟動 uWSGI 來運行一個 HTTP 服務器,將程序部署在HTTP端口 9090 上:
uwsgi --http :9090 --wsgi-file foobar.py添加并發和監控
默認情況下,uWSGI 啟動一個單一的進程和一個單一的線程。
你可以用 –processes 選項添加更多的進程,或者使用 –threads 選項添加更多的線程 ,也可以兩者同時使用。
uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2以上命令將會生成 4 個進程, 每個進程有 2 個線程。
如果你要執行監控任務,可以使用 stats 子系統,監控的數據格式是 JSON:
uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191我們可以安裝 uwsgitop(類似 Linux top 命令) 來查看監控數據:
pip install uwsgitop參考鏈接:https://www.runoob.com/python3/python-uwsgi.html
總結
以上是生活随笔為你收集整理的Python 安装 uWSGI并运行一个入门示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【收藏】在 ubuntu21.04 中使
- 下一篇: Python 实例属性和类属性