diff options
| author | th3nn3ss <chuksmcdennis@yahoo.com> | 2022-12-21 14:25:24 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-03 14:01:48 +0200 |
| commit | 1d1ddffc27cd55c011298cd09bfa4de3fa73cf7a (patch) | |
| tree | c77c385a04bb16b84bab217258356cc480a85abc /docs | |
| parent | 4e4eda6d6c8a5867dafd2ba9167ad8c064bb644a (diff) | |
Fixed #33738 -- Allowed handling ASGI http.disconnect in long-lived requests.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/5.0.txt | 7 | ||||
| -rw-r--r-- | docs/topics/async.txt | 20 |
2 files changed, 27 insertions, 0 deletions
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt index 6e911f471e..cc4fb69ee3 100644 --- a/docs/releases/5.0.txt +++ b/docs/releases/5.0.txt @@ -192,6 +192,13 @@ Minor features * ... +Asynchronous views +~~~~~~~~~~~~~~~~~~ + +* Under ASGI, ``http.disconnect`` events are now handled. This allows views to + perform any necessary cleanup if a client disconnects before the response is + generated. See :ref:`async-handling-disconnect` for more details. + Cache ~~~~~ diff --git a/docs/topics/async.txt b/docs/topics/async.txt index 95d3435e07..5a2324af5e 100644 --- a/docs/topics/async.txt +++ b/docs/topics/async.txt @@ -136,6 +136,26 @@ a purely synchronous codebase under ASGI because the request-handling code is still all running asynchronously. In general you will only want to enable ASGI mode if you have asynchronous code in your project. +.. _async-handling-disconnect: + +Handling disconnects +-------------------- + +.. versionadded:: 5.0 + +For long-lived requests, a client may disconnect before the view returns a +response. In this case, an ``asyncio.CancelledError`` will be raised in the +view. You can catch this error and handle it if you need to perform any +cleanup:: + + async def my_view(request): + try: + # Do some work + ... + except asyncio.CancelledError: + # Handle disconnect + raise + .. _async-safety: Async safety |
