diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-04-13 00:36:52 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-04-13 00:36:52 (GMT) |
commit | 0cab9c1ebaa11bb7838a552c671c903156262ab7 (patch) | |
tree | 640bcabc8876c74c7ba53231551613cfb9a34600 /Lib/wsgiref/simple_server.py | |
parent | 7258176c68a5061a5d05ee43f11e99fd94e34364 (diff) | |
download | cpython-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.py | 13 |
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 |