Skip to content
Myr

Update documentation on asyncio background tasks

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

This has been an early question from users, so best to explain.

authored by pgjones · committed by pgjones · parent 1c3b53c · Browse files · 2 files+19 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

2 files+19 added−0 removed

  • other:+19 added−0 removed

2 files+19 added−0 removed

modified:docs/deploying/asgi.rst+2 added
1.. _asgi:23ASGI4====56If you'd like to use an ASGI server you will need to utilise WSGI to
23 unmodified lines
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