Skip to content

Commit

Permalink
Add note about tasks that should be cancelled on shutdown (#8267)
Browse files Browse the repository at this point in the history
(cherry picked from commit 509fb26)
  • Loading branch information
Dreamsorcerer authored and patchback[bot] committed Mar 29, 2024
1 parent 286f50c commit 27c8d61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/8267.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a note about canceling tasks to avoid delaying server shutdown -- by :user:`Dreamsorcerer`.
8 changes: 8 additions & 0 deletions docs/web_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,14 @@ steps 4 and 7).
:ref:`cleanup contexts<aiohttp-web-cleanup-ctx>`.
7. Cancel any remaining tasks and wait on them to complete.

.. note::

When creating new tasks in a handler which _should_ be cancelled on server shutdown,
then it is important to keep track of those tasks and explicitly cancel them in a
:attr:`Application.on_shutdown` callback. As we can see from the above steps,
without this the server will wait on those new tasks to complete before it continues
with server shutdown.

Websocket shutdown
^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit 27c8d61

Please sign in to comment.