In this article, we are sharing an example of how Tornado handles high concurrency as follows:
#!/bin/env python # -*- coding:utf-8 -*- import import import import import from import run_on_executor from import ThreadPoolExecutor import time from import define, options define("port", default=8000, help="run on the given port", type=int) class SleepHandler(): executor = ThreadPoolExecutor(2) @ @ def get(self): # If you perform an asynchrony that returns a value to be called again, you can do this (just for demonstration purposes), otherwise you can just field it. res = yield () ("when i sleep %s s" % res) () @run_on_executor def sleep(self): (5) return 5 class JustNowHandler(): def get(self): ("i hope just now see you") if __name__ == "__main__": .parse_command_line() app = (handlers=[ (r"/sleep", SleepHandler), (r"/justnow", JustNowHandler)]) http_server = (app) http_server.listen() ().start()
summarize
Above is this article on Tornado high concurrency processing method example code of all content, I hope to help you. Interested friends can continue to refer to other related topics on this site, if there are inadequacies, welcome to leave a message to point out. Thank you for the support of friends on this site!