Python advanced ing--Create your first tornado appCategory: Python2013-06-02 23:02 1725 people read Comments (2) favorite reports Pythontornado
Every day in the group with a lot of friends to discuss some issues, feel that their technical upgrading has a great help, but also can brainstorm, learn some of their own previously never touched things, such as tornado, recently heard a lot of friends in the group are discussing this, so I also follow the follow-up understanding.
Tornado is an efficient and extensible non-blocking Web server and its associated tools open source version, and the current mainstream Web server framework compared to the obvious difference is that it is a non-blocking server, and very fast, thanks to its non-blocking mode and the rational use of epoll. After a simple understanding, let's look at how to install and use.
For installation, there can be many ways, such as manually compiled source code, or with Easy_install, or with PIP installation, here I use the PIP installation method, only need a command, convenient and fast, after all, with a virtual keyboard knocking hand pain, command as follows:
[Python]View Plaincopy
- Pip Install Tornado
Wait for the installation to complete.
Then let's take a look at the first Hello World example:
[Python]View Plaincopy
- #!/usr/bin/env python
- #-*-Coding:utf-8-*-
- #
- # Authhor:Eric.Tang
- # email: [Email protected]
- # date:13/06/02 22:17:57
- # Desc:hello,world of tornado
- #
- 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 ()
Then save as hellotornado.py.
Then we can execute this file, then we have a different way of doing it, modify the permissions of the py file, make it executable, or execute the Python hellotornado.py directly on the command line, both of which are possible.
After launch, we can enter localhost:8888 in the address bar in the browser, and then enter, you can see the effect is as follows:
OK, the whole blog is also written on the tablet computer, Tornado is also running on this, now the power is below 30%, the touch screen a bit floating serves, the shutdown charge, tomorrow on the road can continue to learn. Good night!
Python advanced ing--Create your first tornado app