diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-10 09:24:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-10 09:24:22 (GMT) |
commit | 7853c769067699c79c0d4fe4967e9d8f8b8b0a5e (patch) | |
tree | c536a6805508bb86fef274d42f913158f02581fc | |
parent | a71500cd2446ac460610c8d57951d02ea37b0bb6 (diff) | |
download | cpython-7853c769067699c79c0d4fe4967e9d8f8b8b0a5e.zip cpython-7853c769067699c79c0d4fe4967e9d8f8b8b0a5e.tar.gz cpython-7853c769067699c79c0d4fe4967e9d8f8b8b0a5e.tar.bz2 |
[3.12] GH-106684: Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) (#107656)
GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (GH-107650)
(cherry picked from commit 41178e41995992bbe417f94bce158de93f9e3188)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
-rw-r--r-- | Lib/asyncio/streams.py | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index bf15f51..14861df 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -392,6 +392,10 @@ class StreamWriter: self._transport = new_transport protocol._replace_writer(self) + def __del__(self): + if not self._transport.is_closing(): + self.close() + class StreamReader: diff --git a/Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst b/Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst new file mode 100644 index 0000000..85bce76 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst @@ -0,0 +1 @@ +Close :class:`asyncio.StreamWriter` when it is not closed by application leading to memory leaks. Patch by Kumar Aditya. |