import threading from http.server import BaseHTTPRequestHandler, HTTPServer # Define the HTTP request handler class class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): # Override the do_GET method to handle GET requests def do_GET(self): # Set the response status code self.send_response(200) # Set the response headers self.send_header('Content-type', 'text/html') self.end_headers() # Write the response content self.wfile.write(b"Hello, world!") # Define the HTTP server class class ThreadedHTTPServer(HTTPServer): # Override the process_request method to handle each request in a separate thread def process_request(self, request, client_address): # Create a new thread for each request t = threading.Thread(target=self.__new_request_thread, args=(request, client_address)) # Start the thread t.start() # Method to handle each request in a separate thread def __new_request_thread(self, request, client_address): # Call the superclass's process_request method to handle the request super().process_request(request, client_address) # Main function to run the server def main(): # Define the server address and port server_address = ('', 8000) # Create an instance of the threaded HTTP server httpd = ThreadedHTTPServer(server_address, SimpleHTTPRequestHandler) print("Server started on port 8000...") # Start serving HTTP requests httpd.serve_forever() if __name__ == '__main__': main()