Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
import threading
import time
import sys
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
print("active threads: ", str(threading.active_count()))
self.send_response(200)
self.end_headers()
self.wfile.write(b'Request Processed\n')
time.sleep(self.server.delay)
class MultiThreadedServer(ThreadingHTTPServer):
def __init__(self, host, port, delay):
super().__init__((host, port), RequestHandler)
self.delay = delay
if __name__ == '__main__':
if len(sys.argv) !=4:
print('usage: ' + sys.argv[0] + ' <host> <port> <delay>')
sys.exit()
host = sys.argv[1]
port = int(sys.argv[2])
delay = int(sys.argv[3])
server = MultiThreadedServer(host, port, delay)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment