Skip to content

Instantly share code, notes, and snippets.

@return-none
Last active August 29, 2015 14:03
Show Gist options
  • Save return-none/c91f55ac8be443b83c96 to your computer and use it in GitHub Desktop.
Save return-none/c91f55ac8be443b83c96 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Simple python HTTP server. Added nice messages.
Place to /usr/local/bin/serve, chmod and run. Provide port as second argument
TODO: handle port is busy excepion
"""
from sys import argv
import SimpleHTTPServer
import SocketServer
PORT = int(argv[1]) if argv[1:] else 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print "Server stopped"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment