Python advanced ing--Create your first tornado app

Source: Internet
Author: User

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
    1. Pip Install Tornado

Wait for the installation to complete.

Then let's take a look at the first Hello World example:

[Python]View Plaincopy
  1. #!/usr/bin/env python
  2. #-*-Coding:utf-8-*-
  3. #
  4. # Authhor:Eric.Tang
  5. # email: [Email protected]
  6. # date:13/06/02 22:17:57
  7. # Desc:hello,world of tornado
  8. #
  9. Import Tornado.ioloop
  10. Import Tornado.web
  11. Class MainHandler (Tornado.web.RequestHandler):
  12. def get (self):
  13. self.write ("Hello, World")
  14. application = Tornado.web.Application ([
  15. (R"/", MainHandler),
  16. ])
  17. If __name__=="__main__":
  18. Application.listen (8888)
  19. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.