Tornado (web server)#Example

{{Short description|Python web server and application framework}}

{{multiple issues|

{{notability|Products|date=March 2019}}

{{third-party|date=March 2019}}

}}

{{Infobox software

| name = Tornado

| logo = TornadoWebServerLogo.png

| screenshot =

| caption =

| author = FriendFeed

| developer = Ben Darnell, Meta, Bret Taylor

| released = {{Start date and age|2009}}

| latest release version = {{wikidata|property|reference|edit|P348}}

| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}

| repo = {{URL|https://github.com/tornadoweb/tornado|Tornado Repository}}

| programming language = Python

| operating system = Cross-platform

| language = English

| genre = Web server

| license = Apache licence 2.0

}}

Tornado is a scalable, non-blocking web server and web application framework written in Python.{{cite web | url=https://github.com/tornadoweb/tornado/wiki | title=Home - tornado - GitHub | publisher=GitHub | access-date=2009-09-10}} It was developed for use by FriendFeed; the company was acquired by Facebook in 2009 and Tornado was open-sourced soon after.{{cite web | url=http://news.cnet.com/8301-17939_109-10349836-2.html | title=Facebook open-sources real-time FriendFeed facet | publisher=CNet | access-date=2009-09-10 | archive-date=2012-01-30 | archive-url=https://web.archive.org/web/20120130112658/http://news.cnet.com/8301-17939_109-10349836-2.html | url-status=dead }}

Performance

Tornado is noted for its high performance. Its design enables handling a large number of concurrent connections (i.e., tries to solve the "C10k problem").

Modules

  • An asynchronous MongoDB driver called Motor.
  • CouchDB drivers called corduroy and trombi.
  • Asynchronous driver for PostgreSQL wrapping psycopg called Momoko

Example

The following code shows a simple web application that displays "Hello World!" when visited:{{cite web| url=https://www.tornadoweb.org/en/stable/#hello-world |title=Hello, world |access-date=2022-09-14}}

import asyncio

import tornado.web

class MainHandler(tornado.web.RequestHandler):

def get(self):

self.write("Hello, world")

def make_app():

return tornado.web.Application([(r"/", MainHandler),])

async def main():

app = make_app()

app.listen(8888)

await asyncio.Event().wait()

if __name__ == "__main__":

asyncio.run(main())

See also

References

{{Reflist|2}}