From 2eb4bdf0772938b1293b893598b968d3419d4ddb Mon Sep 17 00:00:00 2001 From: Kanishk Pachauri Date: Tue, 18 Mar 2025 09:27:05 +0000 Subject: [PATCH] gh-130132: properly free resources in `urrlib.urlopen` examples (GH-130280) (cherry picked from commit 77d2fd441320ca365c34e21c475d3878f3d5d833) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kanishk Pachauri Co-authored-by: sobolevn Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/urllib.request.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index 0c5aa0458c6ebe..5d1d8a245907c6 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1244,7 +1244,10 @@ It is also possible to achieve the same result without using the >>> import urllib.request >>> f = urllib.request.urlopen('http://www.python.org/') - >>> print(f.read(100).decode('utf-8')) + >>> try: + ... print(f.read(100).decode('utf-8')) + ... finally: + ... f.close()