- 浏览: 242213 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (127)
- vim (3)
- python (44)
- pymysql (1)
- mysql (9)
- macvim (1)
- erlang (3)
- twisted (0)
- tornado (5)
- django (7)
- postgresql (5)
- sql (1)
- java (7)
- tech (4)
- cache (1)
- lifestyle (3)
- html (1)
- ubuntu (2)
- rabbitmq (1)
- algorithm (8)
- Linux (4)
- Pythonista (1)
- thread (1)
- sort (6)
- 设计模式 (1)
- search (1)
- Unix (6)
- Socket (3)
- C (2)
- web (1)
- gc (1)
- php (10)
- macos (1)
最新评论
-
2057:
这个程序有bug。
查找算法学习之二分查找(Python版本)——BinarySearch -
dotjar:
NB
一个Python程序员的进化[转]
Thread-safety notes:
In general, methods on RequestHandler and elsewhere in tornado are not thread-safe. In particular, methods such as write(), finish(), and flush() must only be called from the main thread. If you use multiple threads it is important to use IOLoop.add_callback to transfer control back to the main thread before finishing the request.
Collections:
For example, partial() can be used to create a callable that behaves like the int() function where the base argument defaults to two
一般,函数在执行时,需要带上所必要的参数进行调用。然后,有时参数可以在函数被调用前提前获知。这种情况下,一个函数有一个或多个参数预先就能用上,一遍函数能用更少的参数进行调用。
Decorators:
tornado.web.asynchronous(method)
Wrap request handler methods with this if they are asynchronous.
示例:
tornado.web.authenticated(method)
tornado.web.addslash(method)
tornado.web.removeslash(method)
Others:
一、@property可以把function变成属性。
示例:
Descriptors:
有关另外异步调用tornado.gen以及generator的用法会在下一篇进行整理。参考资料:
http://joy2everyone.iteye.com/blog/910950
http://docs.python.org/2/library/functools.html
http://www.tornadoweb.org/documentation/web.html
http://docs.python.org/2/library/functions.html#property
http://www.ibm.com/developerworks/library/os-pythondescriptors/index.html
http://stackoverflow.com/questions/6618002/python-property-versus-getters-and-setters
http://stackoverflow.com/questions/3252228/python-why-is-functools-partial-necessary
引用
In general, methods on RequestHandler and elsewhere in tornado are not thread-safe. In particular, methods such as write(), finish(), and flush() must only be called from the main thread. If you use multiple threads it is important to use IOLoop.add_callback to transfer control back to the main thread before finishing the request.
Collections:
- 1、functools.partial用法
- 2、tornado.web.asynchronous用法
引用
functools.partial(func[,*args][, **keywords])Return a new partial object which when called will behave like func called with the positional arguments args and keyword arguments keywords. If more arguments are supplied to the call, they are appended to args. If additional keyword arguments are supplied, they extend and override keywords.
For example, partial() can be used to create a callable that behaves like the int() function where the base argument defaults to two
>>> import functors >>> f=functools.partial(int, base=2) >>> f.args () >>> f.func <type 'int'> >>> f.keywords {'base': 2}
>>>from functools imports partial >>>basetwo = partial(int, base=2) >>>basetwo('10010') 18
一般,函数在执行时,需要带上所必要的参数进行调用。然后,有时参数可以在函数被调用前提前获知。这种情况下,一个函数有一个或多个参数预先就能用上,一遍函数能用更少的参数进行调用。
Decorators:
tornado.web.asynchronous(method)
Wrap request handler methods with this if they are asynchronous.
引用
If this decorator is given, the response is not finished when the method returns. It is up to the request handler to call self.finish() to finish the HTTP request. Without this decorator, the request is automatically finished when the get() or post() method returns.
class MyRequestHandler(web.RequestHandler): @web.asynchronous def get(self): http = httpclient.AsyncHTTPClient() http.fetch("http://friendfeed.com/", self._on_download) def _on_download(self, response): self.write("Downloaded!") self.finish()
示例:
#!/usr/bin/env python #-*-coding:utf-8-*- import tornado import functors import tornado.httpserver from tornado.web import RequestHandler from tornado.httpclient import AsyncHTTPClient class AsyncHandler(RequestHandler): @tornado.web.asynchronous def get(self): http_client = AsyncHTTPClient() http_client.fetch("http://www.google.com", callback=functools.partial(self.on_fetch,'love it')) def on_fetch(self, param, response): print response.body print param self.write('This is a demo.') self.finish() settings = { "debug": True, } application = tornado.web.Application([ (r"/", AsyncHandler), ], **settings) if __name__ == "__main__": http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8088) tornado.ioloop.IOLoop.instance().start()
tornado.web.authenticated(method)
引用
Decorate methods with this to require that the user be logged in.
tornado.web.addslash(method)
引用
Use this decorator to add a missing trailing slash to the request path.
For example, a request to ‘/foo’ would redirect to ‘/foo/’ with this decorator. Your request handler mapping should use a regular expression like r’/foo/?’ in conjunction with using the decorator.
For example, a request to ‘/foo’ would redirect to ‘/foo/’ with this decorator. Your request handler mapping should use a regular expression like r’/foo/?’ in conjunction with using the decorator.
tornado.web.removeslash(method)
引用
Use this decorator to remove trailing slashes from the request path.
For example, a request to '/foo/' would redirect to '/foo' with this decorator. Your request handler mapping should use a regular expression like r'/foo/*'in conjunction with using the decorator.
For example, a request to '/foo/' would redirect to '/foo' with this decorator. Your request handler mapping should use a regular expression like r'/foo/*'in conjunction with using the decorator.
Others:
一、@property可以把function变成属性。
引用
property([fget[,fset[,fdel[,doc]]]])Return a property attribute for new-style classes (classes that derive from object).
If given, doc will be the docstring of the property attribute. Otherwise, the property will copy fget‘s docstring (if it exists). This makes it possible to create read-only properties easily using property() as a decorator:
示例:
class Person(object): def __init__(self): self._name = '' def fget(self): print "Getting: %s" % self._name return self._name def fset(self, value): print "Setting: %s" % value self._name = value.title() def fdel(self): print "Deleting: %s" %self._name del self._name name = property(fget, fset, fdel, "I'm the property.") p=Person() p.name='Eric Su' p.name del p.name
引用
A property object has getter, setter, and deleter methods usable as decorators that create a copy of the property with the corresponding accessor function set to the decorated function.
Descriptors:
class Person(object): def __init__(self): self._name = '' @property def name(self): print "Getting: %s" % self._name return self._name @name.setter def name(self, value): print "Setting: %s" % value self._name = value.title() @name.deleter def name(self): print "Deleting: %s" % self._name del self._name p=Person() p.name='Eric Su' p.name del p.name
有关另外异步调用tornado.gen以及generator的用法会在下一篇进行整理。参考资料:
http://joy2everyone.iteye.com/blog/910950
http://docs.python.org/2/library/functools.html
http://www.tornadoweb.org/documentation/web.html
http://docs.python.org/2/library/functions.html#property
http://www.ibm.com/developerworks/library/os-pythondescriptors/index.html
http://stackoverflow.com/questions/6618002/python-property-versus-getters-and-setters
http://stackoverflow.com/questions/3252228/python-why-is-functools-partial-necessary
发表评论
-
macos 10.9.2 clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command
2014-03-25 19:13 1730方法总是有的,当然需要你去寻找。 当然如果花费太多的时间在一件 ... -
PostgreSQL psycopg2:IndexError: tuple index out of range
2014-01-09 17:04 2192Postgresql psycopg2使用like查询的时候 ... -
Python 迭代器和生成器
2013-10-15 23:09 2814迭代器 迭代器只不过是一个实现迭代器协议的容器对象。它基于两个 ... -
Python时间模块
2013-10-15 23:03 3428time模块 时间模块中最常用的一个函数就是获取当前时间的函数 ... -
Python装饰器
2013-10-15 22:59 1514编写自定义装饰器有许多方法,但最简单和最容易理解的方法是编写一 ... -
python list
2013-10-15 22:56 1218简单总结以及整理如下: >>> dir( ... -
Python Excel
2013-09-10 17:21 936安装lib easy_install xlrd def ... -
排序算法学习(python版本)之堆排序(HeapSort)
2013-07-01 22:54 1963Contains: 堆排序以及堆排序的应用 堆排序(Heaps ... -
python range xrange
2013-06-25 23:30 1106引用Help on built-in function ran ... -
python class
2013-06-25 00:54 1792引用类是创建新对象类 ... -
AttributeError: 'module' object has no attribute 'SendCloud'
2013-06-05 11:46 7023网上查了下 意思是说你命名的文件名不能和lib重名,这样会导 ... -
python string
2013-05-07 23:44 2164如果这就是字符串,这本来就是字符串 首先看下字符串的方法 ... -
Python property
2013-03-29 19:56 0由于之前有总结过,可以参考http://2057.iteye. ... -
python tips
2013-03-28 23:57 8481、enum #!/usr/bin/env python ... -
python decorators
2013-03-28 23:36 1326Contains: 1、decorators 2、funct ... -
python closures
2013-03-28 22:09 1156Closure:如果在一个内部函数里,对在外部作用域(但不是在 ... -
Python map、filter,reduce介绍
2013-03-28 22:02 12511、filter(function,iterable) 引用C ... -
Python __new__ 、__init__、 __call__
2013-03-26 23:49 5296Contains: __new__: 创建对象时调用,返回当 ... -
Python socket简介
2013-03-25 23:42 2119自豪地使用dir和help. Python 2.7.2 ( ... -
Tornado ioloop源码简析
2013-03-21 00:18 2804#!/usr/bin/env python #-*-en ...
相关推荐
Tornado Web 服务器概览 详细文档
Tornado WebServer
Tornado全称Tornado Web Server,是一个用Python语 言写成的Web服 务器兼Web应用框架,由FriendFeed公 司 在自己的网站FriendFeed中使用,被Facebook收购 以后框架在2009年9月以开源软件形式开放给大众。 特点: 作为...
python3+tornado web简单使用说明
一个基于Tornado Web 框架的简单的RESTFul API库
用tornado搭建web服务,并发高,占用资源少,简单易学
现在非常流行的非阻塞web框架,自带服务器,与nginx绝配
RabbitChat, 在 RabbitMQ Tornado web socket Pika上,一个简单的聊天系统基于 RabbitChatRabbitChat - 基于 RabbitMQ Tornado web socket的简单网络聊天系统。版权所有( C ) 2011,Haridas N haridas.nss@gmail.com...
Tornadoweb服务器入门1[文].pdf
龙卷风-asyntool 一个简单的工具让 tornadoweb 异步运行代码受龙卷风 netutils、解析器的启发
Tornado简介.md
web.py的实例todo的tornado改写版本
资源来自pypi官网。 资源全名:tornadoweb-0.0.7-py2-none-any.whl
得利于其 非阻塞的方式和对 epoll 的运用,Tornado 每秒可以处理数以千计的连接,因此 Tornado 是实时 Web 服务的一个 理想框架。我们开发这个 Web 服务器的主要目的就是为了处理 FriendFeed 的实时功能 ——在 ...
Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本。这个 Web 框架看起来有些像 web.py 或者 Google 的 webapp,不过为了能有效利用非阻塞式服务器环境,这个 Web 框架还包含了一些...
python-tornado框架
tornado作为用户产品后台服务器核心框架 redis 保存session数据、短时间房源信息、地域信息等,保存页面缓存数据,提高服务器响应速度 采用前后端完全分离架构,采用ajax异步调用、json数据传输,使后端接口可以...
一、Tornado简介 Tornado 是 FriendFeed 的 Web 服务器及其常用工具的开源版本。Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的框架)有着明显的区别:它是非阻塞式服务器,而且速度相当快。得利于其 ...
Tornado 是一个用于 Web 服务器的 Python Web 框架和异步网络库。 虽然可以使用按需 ajax 调用将前端与后端 Web 服务完全分离,但有时需要从服务器生成视图,并在最初呈现页面时初始化数据。 安装 先决条件 安装 ...