- 浏览: 246830 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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 1756方法总是有的,当然需要你去寻找。 当然如果花费太多的时间在一件 ... -
PostgreSQL psycopg2:IndexError: tuple index out of range
2014-01-09 17:04 2226Postgresql psycopg2使用like查询的时候 ... -
Python 迭代器和生成器
2013-10-15 23:09 2848迭代器 迭代器只不过是一个实现迭代器协议的容器对象。它基于两个 ... -
Python时间模块
2013-10-15 23:03 3466time模块 时间模块中最常用的一个函数就是获取当前时间的函数 ... -
Python装饰器
2013-10-15 22:59 1566编写自定义装饰器有许多方法,但最简单和最容易理解的方法是编写一 ... -
python list
2013-10-15 22:56 1252简单总结以及整理如下: >>> dir( ... -
Python Excel
2013-09-10 17:21 974安装lib easy_install xlrd def ... -
排序算法学习(python版本)之堆排序(HeapSort)
2013-07-01 22:54 1994Contains: 堆排序以及堆排序的应用 堆排序(Heaps ... -
python range xrange
2013-06-25 23:30 1147引用Help on built-in function ran ... -
python class
2013-06-25 00:54 1826引用类是创建新对象类 ... -
AttributeError: 'module' object has no attribute 'SendCloud'
2013-06-05 11:46 7074网上查了下 意思是说你命名的文件名不能和lib重名,这样会导 ... -
python string
2013-05-07 23:44 2197如果这就是字符串,这本来就是字符串 首先看下字符串的方法 ... -
Python property
2013-03-29 19:56 0由于之前有总结过,可以参考http://2057.iteye. ... -
python tips
2013-03-28 23:57 8811、enum #!/usr/bin/env python ... -
python decorators
2013-03-28 23:36 1364Contains: 1、decorators 2、funct ... -
python closures
2013-03-28 22:09 1186Closure:如果在一个内部函数里,对在外部作用域(但不是在 ... -
Python map、filter,reduce介绍
2013-03-28 22:02 13021、filter(function,iterable) 引用C ... -
Python __new__ 、__init__、 __call__
2013-03-26 23:49 5349Contains: __new__: 创建对象时调用,返回当 ... -
Python socket简介
2013-03-25 23:42 2167自豪地使用dir和help. Python 2.7.2 ( ... -
Tornado ioloop源码简析
2013-03-21 00:18 2847#!/usr/bin/env python #-*-en ...
相关推荐
Tornado Web 服务器概览 详细文档
**Tornado Web Server详解** Tornado Web Server,简称Tornado,是一个开源的、高性能的Web服务器和异步网络库,最初由FriendFeed团队开发,并在2009年开源。后来,Facebook收购了FriendFeed,Tornado也因此成为了...
Tornado全称Tornado Web Server,是一个用Python语 言写成的Web服 务器兼Web应用框架,由FriendFeed公 司 在自己的网站FriendFeed中使用,被Facebook收购 以后框架在2009年9月以开源软件形式开放给大众。 特点: 作为...
python3+tornado web简单使用说明
**Python与Tornado Web框架** Python是一种广泛使用的高级编程语言,尤其在Web开发领域,它以其简洁、易读的语法和强大的库支持而备受青睐。Tornado Web框架是Python中的一个轻量级、高性能的异步网络库,适用于...
"PyPI 官网下载 | tornadoweb-0.0.7-py2-none-any.whl" 这个标题指的是从Python的官方第三方库仓库Python Package Index (PyPI) 下载的一个特定版本的Tornado Web框架,即tornadoweb-0.0.7-py2-none-any.whl。...
#### 一、Tornado Web 服务器简介 Tornado 是一个开源的Python Web 框架以及异步网络库,主要用于编写高性能的Web应用程序和服务。与传统的同步Web框架(如Django)不同,Tornado采用非阻塞的方式处理I/O操作,这...
【Tornado Asyntool:让TornadoWeb异步运行的利器】 Tornado Asyntool 是一个专门针对 TornadoWeb 框架设计的工具,它的主要目标是简化异步代码的编写和执行,使得开发者能更高效地利用 Tornado 的非阻塞I/O模型。...
用tornado搭建web服务,并发高,占用资源少,简单易学
Tornado是一个Python编写的开源Web框架和异步网络库,最初由FriendFeed公司开发。它支持非阻塞网络I/O,使得能够处理成千上万的开放连接,非常适合长轮询、WebSocket和其他需要长期与每个用户保持连接的应用。...
RabbitChat, 在 RabbitMQ Tornado web socket Pika上,一个简单的聊天系统基于 RabbitChatRabbitChat - 基于 RabbitMQ Tornado web socket的简单网络聊天系统。版权所有( C ) 2011,Haridas N haridas.nss@gmail.com...
Tornado 是一个强大的 Python Web 开发框架,以其高性能和异步网络I/O闻名。它最初由 FriendFeed 团队开发,后来被 Facebook 收购并开源。Tornado 的设计目标是处理大量的并发连接,尤其适合长连接和实时Web应用,如...
在Web开发领域,Tornado被广泛用于构建实时Web服务,如聊天应用、实时图表和推送通知等。本实例将探讨如何使用Tornado框架来实现一个简单的Todo应用,它是基于Web.py的Todo应用的改写版本。 首先,我们需要了解...
Python Tornado 框架允许开发者在同一程序中同时运行Web服务器和Socket服务器,并实现它们之间的交互,这在处理实时通信和高性能网络应用时非常有用。本文将详细介绍如何使用Tornado来构建这样的系统。 首先,我们...
示例中没有使用Tornado的异步特性,但通过一个简单的“Hello, world”页面,演示了如何使用Tornado的IOLoop和Web模块来创建Web应用程序。开发者可以将此示例作为入门Tornado Web开发的起点。 文档还提到,与其他...
在 Python 的 Web 开发领域,Tornado 提供了一种轻量级且高效的解决方案,尤其适用于处理大量并发连接,如实时 Web 服务、长轮询和 WebSockets。 **一、Tornado 框架的核心组件** 1. **HTTP Server**: Tornado ...
`tornado.web` 模块是 Tornado Web 框架的核心组成部分。其中 `RequestHandler` 类提供了处理 HTTP 请求的基本方法,如 `get()`、`post()` 等;而 `Application` 类则负责管理整个应用的配置信息和路由表。 **2.2 ...