mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #26404: Add context manager to socketserver, by Aviv Palivoda
This commit is contained in:
parent
7258176c68
commit
0cab9c1eba
11 changed files with 125 additions and 103 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue