Created
February 12, 2013 04:18
-
-
Save hackingbutlegal/4760213 to your computer and use it in GitHub Desktop.
Python web server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SimpleHTTPServer, SocketServer, sys | |
| #SET THE PORT VARIABLE TO COMMAND-LINE ARGUMENT | |
| PORT = sys.argv[1] | |
| def RunServer(): | |
| try: | |
| httphandler = SimpleHTTPServer.SimpleHTTPRequestHandler | |
| httpd = SocketServer.TCPServer(("", int(PORT)), httphandler) | |
| print "Python Web Server, serving at port" + PORT | |
| httpd.serve_forever() | |
| except (KeyboardInterrupt, SystemExit): | |
| print "Exiting..." | |
| sys.exit | |
| except: | |
| print "There was a problem starting the webserver at port " + PORT | |
| RunServer() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment