安裝uwsgi
pip install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple
安裝不上則使用以下命令:
conda install -c conda-forge uwsgi
當(dāng)您成功安裝uwsgi后,您可以通過以下步驟來測試uwsgi是否安裝成功:
創(chuàng)建一個Python腳本,例如app.py,其中包含以下內(nèi)容:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
在終端中,使用以下命令啟動uwsgi服務(wù)器:
uwsgi --http :8000 --wsgi-file app.py
如果一切順利,您將看到類似以下的輸出:文章來源:http://www.zghlxwxcb.cn/news/detail-811330.html
*** Starting uWSGI 2.0.19.1 (64bit) on [Tue Sep 28 10:00:00 2021] ***
compiled with version: 9.3.0 on 28 September 2021 09:59:59
os: Linux-5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021
nodename: your_hostname
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /path/to/your/app
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 4096
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 12345)
uwsgi socket 0 bound to TCP address 127.0.0.1:1234 fd 3
Python version: 3.8.10 (default, May 3 2021, 08:49:41) [GCC 9.3.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55a5e5e7b9c0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72928 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55a5e5e7b9c0 pid: 12345 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 12345, cores: 1)
文章來源地址http://www.zghlxwxcb.cn/news/detail-811330.html
到了這里,關(guān)于在生產(chǎn)環(huán)境中使用uWSGI來運行Flask應(yīng)用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!