翻译自:Asynchronous programming with Tornado
对于初学者来说异步编程很令人迷惑,因此我觉得有必要介绍一些有用的基本概念来帮助初学者避免一些常见的陷阱。如果希望理解通用的异步编程模型,可以查看以下这些网络资源,Introduction to Asynchronous Programming,Twisted Introduction。在这篇文章中我将会着眼于如何使用 Tornado 进行异步编程。
来自Tornado主页的一段话:
FriendFeed’s web server is a relatively simple, non-blocking web server written in Python. The FriendFeed application is written using a web framework that looks a bit like web.py or Google’s webapp, but with additional tools and optimizations to take advantage of the non-blocking web server and tools. Tornado is an open source version of this web server and some of the tools we use most often at FriendFeed. The framework is distinct from most mainstream web server frameworks (and certainly most Python frameworks) because it is non-blocking and reasonably fast. Because it is non-blocking and uses epoll or kqueue, it can handle thousands of simultaneous standing connections, which means the framework is ideal for real-time web services. We built the web server specifically to handle FriendFeed’s real-time features every active user of FriendFeed maintains an open connection to the FriendFeed servers. (For more information on scaling servers to support thousands of clients, see The C10K problem.)
对于初学者首先需要认清的是自己是否真的需要异步操作。异步编程比同步编程复杂得多,因此有人说:异步编程是不适合人类大脑的。