Skip to content

Commit

Permalink
[PR #8267/509fb269 backport][3.9] Add note about tasks that should be…
Browse files Browse the repository at this point in the history
… cancelled on shutdown (#8268)

**This is a backport of PR #8267 as merged into master
(509fb26).**

Co-authored-by: Sam Bull <[email protected]>
  • Loading branch information
patchback[bot] and Dreamsorcerer authored Mar 30, 2024
1 parent eaddd9c commit 3a13bd5
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 3a13bd5

Please sign in to comment.