level 7
cloveses
楼主
FriendFeed’s web server 使用Python语产的简洁、非阻塞WEB服务。FriendFeed应用由像web.py或Google's webapp的WEB框架写成,而且应用高级的非阻塞 web server。
Tornado是开源版本的web服务器,其中使用了FriendFeed应用的一些工具。因非阻塞而快速,而区别于绝大多数主流web服务器框架(当然包括Python 框架)。它使用epoll或kqueue。 经典“Hello World”如下: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将URL或URL模式映射到tornado.web.RequestHandler的子类。这些类中定义get()或post()方法来处理URL的HTTP GET或POST请求。下例中将根URL/映射到MainHandler,将URL模式 /story/([0-9]+)映射到StoryHandler。正则表达式组作为参数传给RequestHandler方法:
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("You requested the main page")
class StoryHandler(tornado.web.RequestHandler):
....def get(self, story_id):
........self.write("You requested the story " + story_id)
application = tornado.web.Application([
....(r"/", MainHandler),
....(r"/story/([0-9]+)", StoryHandler),
])
2013年05月09日 08点05分
1
Tornado是开源版本的web服务器,其中使用了FriendFeed应用的一些工具。因非阻塞而快速,而区别于绝大多数主流web服务器框架(当然包括Python 框架)。它使用epoll或kqueue。 经典“Hello World”如下: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将URL或URL模式映射到tornado.web.RequestHandler的子类。这些类中定义get()或post()方法来处理URL的HTTP GET或POST请求。下例中将根URL/映射到MainHandler,将URL模式 /story/([0-9]+)映射到StoryHandler。正则表达式组作为参数传给RequestHandler方法:
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("You requested the main page")
class StoryHandler(tornado.web.RequestHandler):
....def get(self, story_id):
........self.write("You requested the story " + story_id)
application = tornado.web.Application([
....(r"/", MainHandler),
....(r"/story/([0-9]+)", StoryHandler),
])