Skip to content

Commit 509fb26

Browse files
Add note about tasks that should be cancelled on shutdown (#8267)
1 parent 2434bfe commit 509fb26

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
@@ -956,6 +956,14 @@ steps 4 and 7).
956956
:ref:`cleanup contexts<aiohttp-web-cleanup-ctx>`.
957957
7. Cancel any remaining tasks and wait on them to complete.
958958

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

0 commit comments

Comments
 (0)