Skip to content

Commit

Permalink
Make http.server main program nicer for interactive use.
Browse files Browse the repository at this point in the history
Remove unreachable calls to test().

This restores the behavior of SimpleHTTPServer, where a user could
type "python -m SimpleHTTPServer" and get a simple server for sharing
files. Now, you can do the same thing with "python3 -m http.server".
  • Loading branch information
avassalotti committed Apr 3, 2009
1 parent 3cde7c7 commit b5292a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,12 @@ def test(HandlerClass = BaseHTTPRequestHandler,

sa = httpd.socket.getsockname()
print("Serving HTTP on", sa[0], "port", sa[1], "...")
httpd.serve_forever()

try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
httpd.server_close()
sys.exit(0)

if __name__ == '__main__':
test(HandlerClass=BaseHTTPRequestHandler)
test(HandlerClass=SimpleHTTPRequestHandler)
test(HandlerClass=CGIHTTPRequestHandler)

0 comments on commit b5292a2

Please sign in to comment.