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的 ...
随机推荐
- 7.Java中的字符串
1.String的特性 特性一:不可变性 String s=new String("yangyun") s=s.toUpperCase(); 这里的s,s占用的空间是不一样的(地址 ...
- 朴素贝叶斯算法的python实现
朴素贝叶斯 算法优缺点 优点:在数据较少的情况下依然有效,可以处理多类别问题 缺点:对输入数据的准备方式敏感 适用数据类型:标称型数据 算法思想: 朴素贝叶斯比如我们想判断一个邮件是不是垃圾邮件,那么 ...
- nodejs review-03
39 Serve different file types with our server 处理文件类型 function content_type(filename) { var ext = pat ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- 2016最新 wamp2.5+windows 10安装CoedSgniffer代码格式检查:5分钟安装 30分钟入门和浏览常用命令
14:59 2016/1/112016最新 wamp2.5+windows 10安装CoedSgniffer代码格式检查:注意问题:1.手动安装2.5.0和pear安装方式都成功但是执行时无任何反映, ...
- ZeroMQ接口函数之 :zmq_msg_set - 设置消息的性质
ZeroMQ 官方地址 :http://api.zeromq.org/4-1:zmq_msg_set zmq_msg_set(3) ØMQ Manual - ØMQ/3.2.5 Name zmq_m ...
- ZeroMQ接口函数之 :zmq_send_const – 从一个socket上发送一个固定内存数据
ZeroMQ API 目录 :http://www.cnblogs.com/fengbohello/p/4230135.html ——————————————————————————————————— ...
- ArrayList 实现删除重复元素(元素为对象类型)
package 集合; import java.util.ArrayList;import java.util.Iterator; /* * 删除集合中的重复的元素(元素是对象形式的) * * Li ...
- [IOS] 利用@IBInspectable
某些uiview中设置 这个关键字 IBInspectable 可以让其设置的属性,在右侧的属性栏目里面进行直接设置, 这是最近看了一下wwdc的一个视频学习到的,可以方便的进行 UI的测试,
- JavaScript之闭包就是个子公司
在计算机科学中,闭包(Closure)是词法闭包(Lexical Closure)的简称,是引用了自由变量的函数.这个被引用的自由变量将和这个函数一同存在,即使已经离开了创造它的环境也不例外.所以,有 ...