在生产环境中使用uWSGI来运行Flask应用

安装uwsgi

pip install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple

安装不上则使用以下命令:

conda install -c conda-forge uwsgi 

当您成功安装uwsgi后,您可以通过以下步骤来测试uwsgi是否安装成功:

创建一个Python脚本,例如app.py,其中包含以下内容:

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]

在终端中,使用以下命令启动uwsgi服务器:

uwsgi --http :8000 --wsgi-file app.py

如果一切顺利,您将看到类似以下的输出:

*** 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)

在这里插入图片描述

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值