[Django] #33755: Move ASGi body-file cleanup into ASGIRequest

3 views
Skip to first unread message

Django

unread,
May 31, 2022, 3:04:05 AM5/31/22
to django-...@googlegroups.com
#33755: Move ASGi body-file cleanup into ASGIRequest
------------------------------------------------+------------------------
Reporter: Carlton Gibson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Keywords: ASGI
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
In `django/core/handlers/asgi.py` `ASGIHandler.handle()` currently creates
a temporary file, `body_file`, and then maintains responsibility for
closing that once the response is generated in an extend `try...finally`.
In outline:

```
body_file = ...

try:
...
finally:
body_file.close()
```

The `body_file` is passed into the request, via `create_request()` and
`ASGIRequest.__init()`. Conceptually the request object takes ownership of
`body_file` at that point, and ideally it would be responsible for
cleaning it up too, perhaps via a `__del__` implementation.

--
Ticket URL: <https://code.djangoproject.com/ticket/33755>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 31, 2022, 3:04:50 AM5/31/22
to django-...@googlegroups.com
#33755: Move ASGi body-file cleanup into ASGIRequest
-------------------------------------+-------------------------------------

Reporter: Carlton Gibson | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: HTTP handling | Version: dev
Severity: Normal | Resolution:

Keywords: ASGI | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Carlton Gibson:

Old description:

> In `django/core/handlers/asgi.py` `ASGIHandler.handle()` currently
> creates a temporary file, `body_file`, and then maintains responsibility
> for closing that once the response is generated in an extend
> `try...finally`. In outline:
>
> ```
> body_file = ...
>
> try:
> ...
> finally:
> body_file.close()
> ```
>
> The `body_file` is passed into the request, via `create_request()` and
> `ASGIRequest.__init()`. Conceptually the request object takes ownership
> of `body_file` at that point, and ideally it would be responsible for
> cleaning it up too, perhaps via a `__del__` implementation.

New description:

In `django/core/handlers/asgi.py` `ASGIHandler.handle()` currently creates
a temporary file, `body_file`, and then maintains responsibility for
closing that once the response is generated in an extend `try...finally`.
In outline:


{{{
body_file = ...

try:
...
finally:
body_file.close()
}}}

The `body_file` is passed into the request, via `create_request()` and
`ASGIRequest.__init()`. Conceptually the request object takes ownership of
`body_file` at that point, and ideally it would be responsible for
cleaning it up too, perhaps via a `__del__` implementation.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33755#comment:1>

Reply all
Reply to author
Forward
0 new messages