发布于 2014-07-16 00:26:14 | 342 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Tornado 教程,程序狗速度看过来!

Tornado Python Web应用开发框架

Tornado的全称是Torado Web Server,从名字上看就可知道它可以用作Web服务器,但同时它也是一个Python Web的开发框架。最初是在FriendFeed公司的网站上使用,FaceBook收购了之后便开源了出来。


Tornado 4.0 发布,此版本值得关注的特性如下:

  • The tornado.web.stream_request_body decorator allows large files to be uploaded with limited memory usage.

  • Coroutines are now faster and are used extensively throughout Tornado itself. More methods now return Futures, including most IOStreammethods and RequestHandler.flush.

  • Many user-overridden methods are now allowed to return a Futurefor flow control.

  • HTTP-related code is now shared between the tornado.httpserver,tornado.simple_httpclient and tornado.wsgi modules, making support for features such as chunked and gzip encoding more consistent.HTTPServer now uses new delegate interfaces defined in tornado.httputilin addition to its old single-callback interface.

  • New module tornado.tcpclient creates TCP connections with non-blocking DNS, SSL handshaking, and support for IPv6.

向后兼容:

  • tornado.concurrent.Future is no longer thread-safe; useconcurrent.futures.Future when thread-safety is needed.

  • Tornado now depends on the certifipackage instead of bundling its own copy of the Mozilla CA list. This will be installed automatically when using pip or easy_install.

  • This version includes the changes to the secure cookie format first introduced in version 3.2.1, and the xsrf token change in version 3.2.2.  If you are upgrading from an earlier version, see those versions’ release notes.

  • WebSocket connections from other origin sites are now rejected by default. To accept cross-origin websocket connections, override the new method WebSocketHandler.check_origin.

  • WebSocketHandler no longer supports the old draft 76 protocol (this mainly affects Safari 5.x browsers).  Applications should use non-websocket workarounds for these browsers.

  • Authors of alternative IOLoop implementations should see the changes to IOLoop.add_handler in this release.

  • The RequestHandler.async_callback and WebSocketHandler.async_callbackwrapper functions have been removed; they have been obsolete for a long time due to stack contexts (and more recently coroutines).

  • curl_httpclient now requires a minimum of libcurl version 7.21.1 and pycurl 7.18.2.

  • Support for RequestHandler.get_error_html has been removed; override RequestHandler.write_error instead.

其他

更多内容请看这里

Tornado web server 是使用Python编写出來的一个极轻量级、高可伸缩性和非阻塞IO的Web服务器软件,著名的 Friendfeed 网站就是使用它搭建的。

Tornado 跟其他主流的Web服务器框架(主要是Python框架)不同是采用epoll非阻塞IO,响应快速,可处理数千并发连接,特别适用用于实时的Web服务。

要使用它,必须按照以下套件:

1)Python(建议使用Python 2.5 / Python 2.6)
2)Simplejson(建议使用simplejson 2.0.9)
3)cURL(建议使用curl 7.19.7或以上版本)
4)Pycurl(建议使用pycurl 7.16.2.1)
5)Tornado Web Server(这才是主角,版本就照官網上最新的安裝吧)

一个最简单的服务:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

 



历史版本 :
Tornado 4.5.3 发布,Python Web 框架和异步网络库
Tornado 4.3 正式版发布
Tornado 4.2 发布,Python Web 服务器
Tornado 4.0 发布,Web 服务器
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务