Skip to content
Myr

Merge pull request #3967 from pgjones/docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by GitHub · parents 34eb0da, f74cce1 · Browse files · 3 files+47 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+47 added−0 removed

  • other:+47 added−0 removed

3 files+47 added−0 removed

added:docs/deploying/asgi.rst+29 added
1.. _asgi:23ASGI4====56If you'd like to use an ASGI server you will need to utilise WSGI to7ASGI middleware. The asgiref8[WsgiToAsgi](https://github.com/django/asgiref#wsgi-to-asgi-adapter)9adapter is recommended as it integrates with the event loop used for10Flask's :ref:`async_await` support. You can use the adapter by11wrapping the Flask app,1213.. code-block:: python1415 from asgiref.wsgi import WsgiToAsgi16 from flask import Flask1718 app = Flask(__name__)1920 ...2122 asgi_app = WsgiToAsgi(app)2324and then serving the ``asgi_app`` with the asgi server, e.g. using25`Hypercorn <https://gitlab.com/pgjones/hypercorn>`_,2627.. sourcecode:: text2829 $ hypercorn module:asgi_app
modified:docs/deploying/index.rst+1 added
29 unmodified lines
30 uwsgi31 mod_wsgi32 fastcgi33 cgi34 asgi
modified:docs/async-await.rst+17 added
37 unmodified lines
38most use cases, but Flask's async support enables writing and using39code that wasn't possible natively before.404142Background tasks43----------------4445Async functions will run in an event loop until they complete, at46which stage the event loop will stop. This means any additional47spawned tasks that haven't completed when the async function completes48will be cancelled. Therefore you cannot spawn background tasks, for49example via ``asyncio.create_task``.5051If you wish to use background tasks it is best to use a task queue to52trigger background work, rather than spawn tasks in a view53function. With that in mind you can spawn asyncio tasks by serving54Flask with a ASGI server and utilising the asgiref WsgiToAsgi adapter55as described in :ref:`asgi`. This works as the adapter creates an56event loop that runs continually.575859When to use Quart instead60-------------------------6162Flask's async support is less performant than async-first frameworks due
36 unmodified lines