python Gunicorn
1. 简介
Gunicorn(Green Unicorn)是给Unix用的WSGI HTTP 服务器,它与不同的web框架是非常兼容的、易安装、轻、速度快。

2. 示例代码1
def app(environ, start_response):
data = b"Hello World\n"
start_response("200 OK", [
("Content-Type", "test/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
启动
gunicorn -w 4 myapp:app
起来后显示
[2016-12-12 00:20:12 +0000] [11755] [INFO] Starting gunicorn 19.6.0
[2016-12-12 00:20:12 +0000] [11755] [INFO] Listening at: http://127.0.0.1:8000 (11755)
[2016-12-12 00:20:12 +0000] [11755] [INFO] Using worker: sync
[2016-12-12 00:20:12 +0000] [11760] [INFO] Booting worker with pid: 11760
[2016-12-12 00:20:12 +0000] [11761] [INFO] Booting worker with pid: 11761
[2016-12-12 00:20:12 +0000] [11762] [INFO] Booting worker with pid: 11762
[2016-12-12 00:20:12 +0000] [11763] [INFO] Booting worker with pid: 11763
此时,调用http://127.0.0.1:8000
$curl http://127.0.0.1:8000
Hello World
参数说明
-w 处理HTTP请求的worker进程数,以下两种启动方式等价
gunicorn -w 4 myapp:app
gunicorn --workers=4 myapp:app
参考:
-w INT, --workers INT
The number of worker processes for handling requests.
问题:为何调用 http://ip:8000不行呢, 这个是什么请求呢?
默认有-b参数,参考
-b ADDRESS, --bind ADDRESS
The socket to bind. [['127.0.0.1:8000']]
以下方式启动就可以用ip的方式启动了
sudo gunicorn -w -b 0.0.0.0: myapp:app
3. 示例代码2
之前简单的flask方法
from flask import Flask
app = Flask(__name__) @app.route('/hello.world')
def check():
return 'hello world!' if __name__ == '__main__':
app.run()
启动
$sudo gunicorn -b 0.0.0.0: -w myapp3:app
[-- :: +] [] [INFO] Starting gunicorn 19.6.
[-- :: +] [] [INFO] Listening at: http://0.0.0.0:300 (21005)
[-- :: +] [] [INFO] Using worker: sync
[-- :: +] [] [INFO] Booting worker with pid:
[-- :: +] [] [INFO] Booting worker with pid:
[-- :: +] [] [INFO] Booting worker with pid:
[-- :: +] [] [INFO] Booting worker with pid:
测试
$curl localhost:/hello.world
hello world!
4. 启动异常:[ERROR] Connection in use: ('127.0.0.1', 8000)
原因之一是之前启动的进程没有杀死。
注:ctrl+z 是挂起进程,但没有终止。ctrl+c是终止进程。
如果使用了ctrl+z再回到进程中可使用fg命令,这样可以用ctrl+c来关闭进程
python Gunicorn的更多相关文章
- python gunicorn详解
Gunicorn是一个unix上被广泛使用的高性能的Python WSGI UNIX HTTP Server.和大多数的web框架兼容,并具有实现简单,轻量级,高性能等特点. gunicorn 安装 ...
- gunicorn Python部署应用
对于flask应用 启动命令为 python app.py 使用gunicorn启动 pip install gunicorn python gunicorn --workers=7 switch_a ...
- 利用Haproxy搭建 HTTP 请求走私(Request smuggling)环境
Haproxy 介绍 HAProxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用性.负载均衡,以及基于TCP和HTTP的应用程序代理. 请求走私(Request smuggling)概念证 ...
- virtualenv 环境下 Nginx + Flask + Gunicorn+ Supervisor 搭建 Python Web
在这篇文章里,我们将搭建一个简单的 Web 应用,在虚拟环境中基于 Flask 框架,用 Gunicorn 做 wsgi 容器,用 Supervisor 管理进程,然后使用 Python 探针来监测应 ...
- Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 httplib模块 django和web服务器整合 wsgi模块 gunicorn模块
Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 ...
- python之gunicorn的配置
https://www.cnblogs.com/cwp-bg/p/8780204.html python常见的web部署搭配nginx+gunicorn,下面记录一下gunicorn的配置使用. 安装 ...
- 【Python】Centos + gunicorn+flask 报错ImportError: No module named request
今天用Python去下载图片,用到了 urllib.request,这个是python3的方法.python2 使用的是urllib2 遇到了这么个问题后台报错,ImportError: No mod ...
- python独角兽 Flask + Gunicorn
1.构建程序运行所需的虚拟环境 安装Miniconda 创建虚拟环境 添加程序运行依赖包 添加Gunicorn依赖 方式一:最简单的使用 easy_install 安装或者更新 方式二:下载源码安装 ...
- python web开发c6——阿里云上ubuntu+flask+gunicorn+nginx服务器部署(一)简单测试
简述 Nginx在服务器部署中的作用 请求通过Nginx实现反向代理,将请求提交给代理服务器.本文中只用了一台服务器,所以是代理到本机. gunicorn的作用 作为服务器代码的容器.接收Nginx的 ...
随机推荐
- CountDownLatch
使用的实例: @Override public <V> V get(Future<V> future) { final CountDownLatch l = new Count ...
- Android客户端性能优化(魅族资深工程师毫无保留奉献)
本文由魅族科技有限公司资深Android开发工程师degao(嵌入式企鹅圈原创团队成员)撰写,是degao在嵌入式企鹅圈发表的第一篇原创文章,毫无保留地总结分享其在领导魅族多个项目开发中的Androi ...
- 图文:通过sql server 连接mysql
1.在SQL SERVER服务器上安装MYSQL ODBC驱动; 驱动下载地址:http://dev.mysql.com/downloads/connector/odbc/ 2.安装好后,在管理工具- ...
- 《你不知道的JavaScript -- 上卷》笔记 --- 基于ES6新标准
1.let A:let关键字:将变量绑定到所在的任意作用域 function process(){ //do something } //在这个块中定义的内容完事就可以销毁 { let someRea ...
- iOS Safari 中click点击事件失效的解决办法
问题起因: 在微信公众号开发(微站)过程中用jquery的live方法绑定的click事件点击无效(不能执行) 问题描述 当使用委托给一个元素添加click事件时,如果事件是委托到 document ...
- Codeforces 717G Underfail(最小费用最大流 + AC自动机)
题目 Source http://codeforces.com/problemset/problem/717/G Description You have recently fallen throug ...
- c语言指针疑惑[转载]
c99的动态数组是在栈上面开辟的,而new出来的是在堆上面开辟的.栈和堆的地址是从两端相向增长的.栈很小,一般只有几十k,vc6好像是64k.堆很大,在win32的虚拟地址空间可以分配到2g的内存.栈 ...
- OpenSceneGraph控制模型
OpenSceneGraph控制模型 转自:http://www.cppblog.com/eryar/archive/2012/05/28/176538.html 一.简介 对模型的控制就是修改模型的 ...
- arcmap配置的mxd慢的问题
http://www.360doc.com/content/13/0220/09/3046928_266688511.shtml
- jquery.UI.tabs
今天对jquery UI的tabs进行了进一步的了解,目的是想把死板的切换效果变得动感点,不过经过这进一步的了解,发现它并不合适或都说并不能实现我想要的效果,我想要的效果就是类似淘宝商城的banner ...