From 77d2fd441320ca365c34e21c475d3878f3d5d833 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 (#130280) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 b3efde3f1895..969e7daea710 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1249,7 +1249,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()