Vue d'ensemble

Tornado 6.1, publie le 30 octobre 2021, ajoute le support officiel de Python 3.9 et ameliore la compatibilite avec l'ecosysteme asyncio.

Fonctionnalites principales

Support Python 3.9

Tornado 6.1 est pleinement compatible avec Python 3.9, incluant les nouvelles syntaxes de type et l'integration avec les ameliorations d'asyncio.

python
import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    async def get(self):
        self.write({'message': 'Tornado 6.1 avec Python 3.9'})

def make_app():
    return tornado.web.Application([
        (r'/', MainHandler),
    ])

# app = make_app()
# app.listen(8888)
# tornado.ioloop.IOLoop.current().start()

Compatibilite asyncio

L'integration avec asyncio est renforcee : la boucle d'evenements Tornado utilise desormais asyncio par defaut, facilitant le melange avec d'autres bibliotheques async.

python
import asyncio
import tornado.web
from tornado.httpclient import AsyncHTTPClient

async def recuperer_donnees():
    """Utilisation du client HTTP async Tornado."""
    client = AsyncHTTPClient()
    response = await client.fetch('https://httpbin.org/get')
    return response.body.decode()

# Compatible avec asyncio.run()
# resultat = asyncio.run(recuperer_donnees())
# print(resultat)

Sources