Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multithreaded HTTP Server
#1
Hi,

I have a simple HTTP server that processed data request from multiple clients. I'm using Windows Python 3.8 and ThreadedHTTPServer, but that appears to only use threads to accept requests, but don't actually spawn a new thread to process the request. So in this example below, when a request is for doLargeTask(), the server hangs until it finishes the large request, while no other requests are processed.

Many thanks for some guidance.

from http.server import HTTPServer, BaseHTTPRequestHandler, ThreadingHTTPServer
from socketserver import ThreadingMixIn

class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
    pass

class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
	def do_GET(self):
        
		self.send_response(200)
		self.end_headers()
        
          if A: 
		resp = doSmallTask()
                resp = resp.encode('utf-8')
                self.wfile.write(resp)
          if B:
		resp = doLargeTask()
                resp = resp.encode('utf-8')
                self.wfile.write(resp)


	 
httpd = ThreadingHTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 321 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  How do I properly implement restarting a multithreaded python application? MrFentazis 1 588 Jul-17-2023, 09:10 PM
Last Post: JamesSmith
  Multithreaded file transfer from multiple volumes skoobi 2 1,105 Jul-28-2022, 07:52 AM
Last Post: skoobi
  Process the image on the Python HTTP server Aleks 0 3,153 Dec-02-2021, 11:43 PM
Last Post: Aleks
  How to take the tar backup files form remote server to local server sivareddy 0 1,871 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Module : http.server JohnnyCoffee 3 88,251 Jul-07-2020, 04:48 AM
Last Post: ndc85430
  ModuleNotFoundError: No module named 'http.client'; 'http' is not a package abhishek81py 1 15,252 Jun-25-2020, 08:58 AM
Last Post: buran
  Web server (http) JohnnyCoffee 1 1,729 Jun-14-2020, 12:41 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020