tornado README

The project's README from github.com/tornadoweb/tornado. As one markdown file: README.md.

.. image:: docs/tornado.png?raw=true :alt: Tornado Web :align: center

Tornado Web Server

Tornado <http://www.tornadoweb.org>_ is a Python web framework and asynchronous networking library, originally developed at FriendFeed <http://friendfeed.com>. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling <http://en.wikipedia.org/wiki/Push_technology#Long_Polling>, WebSockets <http://en.wikipedia.org/wiki/WebSocket>_, and other applications that require a long-lived connection to each user.

Hello, world

Here is a simple "Hello, world" example web app for Tornado:

.. code-block:: python

import asyncio
import tornado

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

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])

async def main():
    app = make_app()
    app.listen(8888)
    await asyncio.Event().wait()

if __name__ == "__main__":
    asyncio.run(main())

This example does not use any of Tornado's asynchronous features; for that see this simple chat room <https://github.com/tornadoweb/tornado/tree/stable/demos/chat>_.

Documentation

Documentation and links to additional resources are available at https://www.tornadoweb.org

tornado (tornadoweb/tornado)

Searching Database…

22.2K ·GitHub
这是什么?Tornado 是一个 Python Web 框架和异步网络库,最初由 FriendFeed 开发。得益于非阻塞的网络 I/O,它可以支撑数万个并发连接。
它自己就能处理请求,还是需要放在单独的 Web 服务器后面?它自己就能处理流量——README 的标题就是 Tornado Web Server,示例应用也只是调用了 app.listen(8888)。文中没有提到需要单独的 Web 服务器。
怎样让一个最简单的应用跑起来?继承 tornado.web.RequestHandler 并实现一个 get() 方法,把你的 handler 挂到一个 tornado.web.Application 上,在一个异步的 main() 里调用 app.listen(8888),然后用 asyncio.run(main()) 启动。
它是基于 Python 的 asyncio 运行的,还是自带事件循环?它基于 Python 内置的 asyncio:示例应用先开始监听,然后在 main() 里通过 asyncio.Event().wait() 等待,用 asyncio.run(main()) 启动。文中没有提到其他依赖。
用它是不是必须到处写异步代码?不一定。README 指出它的 Hello, world 示例没有用到 Tornado 的任何异步特性;异步是通过一个简单的聊天室示例单独介绍的。
它适合做哪类应用?适合每个用户都保持连接的应用:README 说它非常适合 long polling、WebSockets,以及其他需要与每个用户保持长连接的应用。
Tornado 是从哪来的?它最初由 FriendFeed 开发;GitHub 上的这个仓库从 2009 年 9 月就存在了。
这个项目还活跃吗?从它的元数据看,是的:仓库没有被归档,大约有 22,000 个 star,并且用 GitHub Actions 运行构建和测试的工作流。
Creator
tornadoweb
Size
11.8 MB
Stars
22.2K
Updated
CommitOct 16
Age
17y
Commits · 90 Days