Skip to content

Instantly share code, notes, and snippets.

@hrj
Created August 12, 2015 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrj/c91b46b3e4bba091fef5 to your computer and use it in GitHub Desktop.
Save hrj/c91b46b3e4bba091fef5 to your computer and use it in GitHub Desktop.
Multi-threaded server using python
#!/usr/bin/python
import SocketServer
import BaseHTTPServer
import SimpleHTTPServer
class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
pass
import sys
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8000
server = ThreadingSimpleServer(('', port), SimpleHTTPServer.SimpleHTTPRequestHandler)
try:
while 1:
sys.stdout.flush()
server.handle_request()
except KeyboardInterrupt:
print "Finished"
@hrj
Copy link
Author

hrj commented Aug 12, 2015

Credits: This is adapted from this post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment