Tornado high concurrency Processing Method Instance code, tornado Processing Method

Source: Internet
Author: User

Tornado high concurrency Processing Method Instance code, tornado Processing Method

This article mainly shares an example of Tornado high concurrency processing method, which is as follows:

#! /Bin/env python #-*-coding: UTF-8-*-import tornado. httpserverimport tornado. ioloopimport tornado. optionsimport tornado. webimport tornado. genfrom tornado. concurrent import run_on_executorfrom concurrent. futures import ThreadPoolExecutorimport timefrom tornado. options import define, optionsdefine ("port", default = 8000, help = "run on the given port", type = int) class SleepHandler (tornado. web. requestHandler): executor = ThreadPoolExecutor (2) @ tornado. web. asynchronous @ tornado. gen. coroutine def get (self): # If the asynchronous call you execute will return a value that will be called again, this can be done (just for demonstration). Otherwise, yield will do res = yield self directly. sleep () self. write ("when I sleep % s" % res) self. finish () @ run_on_executor def sleep (self): time. sleep (5) return 5 class JustNowHandler (tornado. web. requestHandler): def get (self): self. write ("I hope just now see you") if _ name _ = "_ main _": tornado. options. parse_command_line () app = tornado. web. application (handlers = [(r "/sleep", SleepHandler), (r "/justnow", JustNowHandler)]) http_server = tornado. httpserver. HTTPServer (app) http_server.listen (options. port) tornado. ioloop. IOLoop. instance (). start ()

Summary

The above is all about the code of the Tornado high concurrency Processing Method Instance. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.