Skip to content

Instantly share code, notes, and snippets.

@mefarazath
Last active May 13, 2019 06:03
Show Gist options
  • Save mefarazath/3e5a304a3d1c8adcaaeffcfa066299ff to your computer and use it in GitHub Desktop.
Save mefarazath/3e5a304a3d1c8adcaaeffcfa066299ff to your computer and use it in GitHub Desktop.
Multithreaded Python HTTP Server
#!/bin/env 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)
print("MultiThreadedHttpServer started on port " + str(port))
try:
while 1:
sys.stdout.flush()
server.handle_request()
except KeyboardInterrupt:
print "Finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment