python 安装 uwsgi并运行一个入门示例 -凯发k8官方网
发布时间:2025/1/21
26
豆豆
凯发k8官方网
收集整理的这篇文章主要介绍了
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
总结
以上是凯发k8官方网为你收集整理的python 安装 uwsgi并运行一个入门示例的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【收藏】在 ubuntu21.04 中使
- 下一篇: