python bottle 简介
from bottle import run if __name__ == '__main__':
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ['<h1>Hello world!</h1>'] run(host='localhost', port=8080, app=application)
from bottle import run
import gevent.monkey
gevent.monkey.patch_all() if __name__ == '__main__':
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ['<h1>Hello world!</h1>'] run(host='localhost', port=8080, app=application, server = 'gevent')
通过server关键字指定web服务器为‘gevent’,输出的第一行变成了:


def __call__(self, environ, start_response):
""" Each instance of :class:'Bottle' is a WSGI application. """
return self.wsgi(environ, start_response)
def wsgi(self, environ, start_response):
""" The bottle WSGI-interface. """
try:
out = self._cast(self._handle(environ))
# rfc2616 section 4.3
if response._status_code in (100, 101, 204, 304)\
or environ['REQUEST_METHOD'] == 'HEAD':
if hasattr(out, 'close'): out.close()
out = []
start_response(response._status_line, response.headerlist)
return out
_handle:处理请求,最终调用到application ,简化后的代码如下:
def _handle(self, environ):
self.trigger_hook('before_request')
route, args = self.router.match(environ)
out = route.call(**args)
self.trigger_hook('after_request')
return out
A Router is an ordered collection of route->target pairs. It is used to efficiently match WSGI requests against a number of routes and return the first target that satisfies the request.
| Name | Homepage | Description |
|---|---|---|
| cgi |
|
Run as CGI script |
| flup | flup | Run as FastCGI process |
| gae | gae | Helper for Google App Engine deployments |
| wsgiref | wsgiref | Single-threaded default server |
| cherrypy | cherrypy | Multi-threaded and very stable |
| paste | paste | Multi-threaded, stable, tried and tested |
| rocket | rocket | Multi-threaded |
| waitress | waitress | Multi-threaded, poweres Pyramid |
| gunicorn | gunicorn | Pre-forked, partly written in C |
| eventlet | eventlet | Asynchronous framework with WSGI support. |
| gevent | gevent | Asynchronous (greenlets) |
| diesel | diesel | Asynchronous (greenlets) |
| fapws3 | fapws3 | Asynchronous (network side only), written in C |
| tornado | tornado | Asynchronous, powers some parts of Facebook |
| twisted | twisted | Asynchronous, well tested but... twisted |
| meinheld | meinheld | Asynchronous, partly written in C |
| bjoern | bjoern | Asynchronous, very fast and written in C |
| auto |
|
Automatically selects an available server adapter |
python bottle 简介的更多相关文章
- python bottle框架
python bottle框架 简介: Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块. Bottl ...
- python bottle框架(WEB开发、运维开发)教程
教程目录 一:python基础(略,基础还是自己看书学吧) 二:bottle基础 python bottle web框架简介 python bottle 框架环境安装 python bottle 框架 ...
- Python+Bottle+Sina SAE快速构建网站
Bottle是新生一代Python框架的代表,利用Bottle构建网站将十分简单. Sina SAE是国内较出名的云平台之一,十分适用于个人网站的开发或创业公司网站开发. 下面将介绍如果通过Pytho ...
- Python的简介以及安装和第一个程序以及用法
Python的简介: 1.Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.自从20世纪90年代初Python语言诞生至今,它逐渐被广泛应用于处理系统管理任务和Web编程.Pytho ...
- 解决基于BAE python+bottle开发上的一系列问题 - artwebs - 博客频道 - CSDN.NET
解决基于BAE python+bottle开发上的一系列问题 - artwebs - 博客频道 - CSDN.NET 解决基于BAE python+bottle开发上的一系列问题 分类: python ...
- [Python] heapq简介
[Python] heapq简介 « Lonely Coder [Python] heapq简介 judezhan 发布于 2012 年 8 月 8 日 暂无评论 发表评论 假设你需要维护一个列表,这 ...
- 让python bottle框架支持jquery ajax的RESTful风格的PUT和DELETE等请求
这两天在用python的bottle框架开发后台管理系统,接口约定使用RESTful风格请求,前端使用jquery ajax与接口进行交互,使用POST与GET请求时都正常,而Request Meth ...
- Python单元测试简介及Django中的单元测试
Python单元测试简介及Django中的单元测试 单元测试负责对最小的软件设计单元(模块)进行验证,unittest是Python自带的单元测试框架. 单元测试与功能测试都是日常开发中必不可少的部分 ...
- Python列表简介和遍历
一.Python3列表简介 1.1.Python列表简介 序列是Python中最基本的数据结构 序列中的每个值都有对应的位置值,称之为索引,第一个索引是0,第二个索引是1,以此类推. Python有6 ...
随机推荐
- The 2014 ACM-ICPC Asia Regional Anshan Online
[A]无向图的双联通子图计数.DP+状态压缩 [B]计算几何(点的旋转) [C]DP+状态压缩 [D]离散数学+DP (感觉可出) [E]概率DP [F]LCT模板题(-_-///LCT是啥!!!!) ...
- RS485中继器电路(转)
源:RS485中继器电路(转) --------以上部分请勿修改!------------- RS-485中继器 由于在双绞线上的电平损耗,RS-485标准通信的最大传输距离是1200米(4000英尺 ...
- 用Quick Cocos2dx做一个连连看(二)
今天完成了以下内容: 1 成对生成SpriteItem 2 重排接口制作完成 3 SpriteItem的选择逻辑 主要代码如下: function MainScene:onEnter() local ...
- Quick Cocos2dx 与 EnterFrame事件
利用EnterFrame做出行走的效果,效果图如下: 具体操作: 1 给self多加一个bg1用作与bg无限循环换位 2 在AnotherScene:onEnter方法里面新增onEnterFrame ...
- 【安卓手机通用】android adb shell 命令大全
浏览:3116 | 更新:2013-10-17 17:05 | 标签:安卓 android 一.[什么是shell] Linux系统的shell作为操作系统的外壳,为用户提供使用操作系统的接口.它是命 ...
- linear-gradient线性渐变
作者:zccst CSS3 Gradient 分为 linear-gradient(线性渐变)和 radial-gradient(径向渐变). 1,在mozila background: -moz-l ...
- [osg]osg显示中文信息
转自:http://www.cnblogs.com/feixiang-peng/articles/3152754.html 写好了在osg中实时显示中文信息的效果.中间遇到两个问题,一个是中文显示,一 ...
- mysql 常用指令
修改表的字符集 88down voteaccepted If you want to change the table default character set and all character ...
- Python科学计算之Pandas
Reference: http://mp.weixin.qq.com/s?src=3×tamp=1474979163&ver=1&signature=wnZn1UtW ...
- Grunt那些事
1.第一步当然是先安装好nodejs里面的npm包管理器咯,若还不知道怎么安装请参考nodejs那些事里面的安装步骤 2.node安装完后,就安装grunt-CLI,如果nodejs直接安装在系统默认 ...