diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-04-12 10:53:33 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-04-12 10:53:33 (GMT) |
commit | 556e08e9b2016121e0984039c7087f52ba064297 (patch) | |
tree | 0c3dcc73147a7887a12a9d3ac75c9213fc12c914 /Doc/library/concurrent.futures.rst | |
parent | 48a724fa33143bcbab2228058d3f59e1813bd49c (diff) | |
parent | 9575e1891ff533318f6dd72ab6f6bd0f9a042014 (diff) | |
download | cpython-556e08e9b2016121e0984039c7087f52ba064297.zip cpython-556e08e9b2016121e0984039c7087f52ba064297.tar.gz cpython-556e08e9b2016121e0984039c7087f52ba064297.tar.bz2 |
Issue #12955: Change the urlopen() examples to use context managers where appropriate.
Patch by Martin Panter.
Diffstat (limited to 'Doc/library/concurrent.futures.rst')
-rw-r--r-- | Doc/library/concurrent.futures.rst | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst index c177340..11b3916 100644 --- a/Doc/library/concurrent.futures.rst +++ b/Doc/library/concurrent.futures.rst @@ -155,8 +155,8 @@ ThreadPoolExecutor Example # Retrieve a single page and report the url and contents def load_url(url, timeout): - conn = urllib.request.urlopen(url, timeout=timeout) - return conn.readall() + with urllib.request.urlopen(url, timeout=timeout) as conn: + return conn.read() # We can use a with statement to ensure threads are cleaned up promptly with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: |