summaryrefslogtreecommitdiffstats
path: root/Lib/wsgiref/simple_server.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-13 00:36:52 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-04-13 00:36:52 (GMT)
commit0cab9c1ebaa11bb7838a552c671c903156262ab7 (patch)
tree640bcabc8876c74c7ba53231551613cfb9a34600 /Lib/wsgiref/simple_server.py
parent7258176c68a5061a5d05ee43f11e99fd94e34364 (diff)
downloadcpython-0cab9c1ebaa11bb7838a552c671c903156262ab7.zip
cpython-0cab9c1ebaa11bb7838a552c671c903156262ab7.tar.gz
cpython-0cab9c1ebaa11bb7838a552c671c903156262ab7.tar.bz2
Issue #26404: Add context manager to socketserver, by Aviv Palivoda
Diffstat (limited to 'Lib/wsgiref/simple_server.py')
-rw-r--r--Lib/wsgiref/simple_server.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py
index 378b316..1807c66 100644
--- a/Lib/wsgiref/simple_server.py
+++ b/Lib/wsgiref/simple_server.py
@@ -156,10 +156,9 @@ def make_server(
if __name__ == '__main__':
- httpd = make_server('', 8000, demo_app)
- sa = httpd.socket.getsockname()
- print("Serving HTTP on", sa[0], "port", sa[1], "...")
- import webbrowser
- webbrowser.open('http://localhost:8000/xyz?abc')
- httpd.handle_request() # serve one request, then exit
- httpd.server_close()
+ with make_server('', 8000, demo_app) as httpd:
+ sa = httpd.socket.getsockname()
+ print("Serving HTTP on", sa[0], "port", sa[1], "...")
+ import webbrowser
+ webbrowser.open('http://localhost:8000/xyz?abc')
+ httpd.handle_request() # serve one request, then exit