update async docs

This commit is contained in:
David Lord 2021-04-06 15:31:28 -07:00
parent 61fbae8664
commit dc3e9c0cc3
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
7 changed files with 109 additions and 65 deletions

View file

@ -171,16 +171,23 @@ Also see the :doc:`/becomingbig` section of the documentation for some
inspiration for larger applications based on Flask.
Async-await and ASGI support
Async/await and ASGI support
----------------------------
Flask supports ``async`` coroutines for view functions, and certain
others by executing the coroutine on a seperate thread instead of
utilising an event loop on the main thread as an async first (ASGI)
frameworks would. This is necessary for Flask to remain backwards
compatibility with extensions and code built before ``async`` was
introduced into Python. This compromise introduces a performance cost
compared with the ASGI frameworks, due to the overhead of the threads.
Flask supports ``async`` coroutines for view functions by executing the
coroutine on a separate thread instead of using an event loop on the
main thread as an async-first (ASGI) framework would. This is necessary
for Flask to remain backwards compatible with extensions and code built
before ``async`` was introduced into Python. This compromise introduces
a performance cost compared with the ASGI frameworks, due to the
overhead of the threads.
Due to how tied to WSGI Flask's code is, it's not clear if it's possible
to make the ``Flask`` class support ASGI and WSGI at the same time. Work
is currently being done in Werkzeug to work with ASGI, which may
eventually enable support in Flask as well.
See :doc:`/async-await` for more discussion.
What Flask is, What Flask is Not