Skip to content

Commit 3a13bd5

Browse files
[PR #8267/509fb269 backport][3.9] Add note about tasks that should be cancelled on shutdown (#8268)
**This is a backport of PR #8267 as merged into master (509fb26).** Co-authored-by: Sam Bull <[email protected]>
1 parent eaddd9c commit 3a13bd5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGES/8267.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a note about canceling tasks to avoid delaying server shutdown -- by :user:`Dreamsorcerer`.

docs/web_advanced.rst

+8
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,14 @@ steps 4 and 7).
952952
:ref:`cleanup contexts<aiohttp-web-cleanup-ctx>`.
953953
7. Cancel any remaining tasks and wait on them to complete.
954954

955+
.. note::
956+
957+
When creating new tasks in a handler which _should_ be cancelled on server shutdown,
958+
then it is important to keep track of those tasks and explicitly cancel them in a
959+
:attr:`Application.on_shutdown` callback. As we can see from the above steps,
960+
without this the server will wait on those new tasks to complete before it continues
961+
with server shutdown.
962+
955963
Websocket shutdown
956964
^^^^^^^^^^^^^^^^^^
957965

0 commit comments

Comments
 (0)