'How to create a http server that сontrol of the socketserver's main loop thread?

I created an http server. My task is to make sure that each new post request to the server is processed in a separate thread.I tried using socketserver.ThreadingTCPServer(),but this way I can't control the threads. I need to start a thread only after the previous one is completed or after 5 minutes have passed.How can I implement the server differently, but only so that requests are processed in a separate request and each new thread is processed after the previous one has completed?

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


class Handler(BaseHTTPRequestHandler):

    def do_POST(self):

        self.send_response(200)
        self.end_headers()
        query_args = parse_qs(urlparse(self.path).query)
        print(query_args)



if __name__ == "__main__":

    try:
        with socketserver.ThreadingTCPServer(("", 8080), Handler) as httpd:
            while True:
                httpd.serve_forever()

    except Exception as e:
        httpd.server_close()



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source