mtwsgi icon indicating copy to clipboard operation
mtwsgi copied to clipboard

Get path at the beginning of request

Open gokh4n opened this issue 6 years ago • 0 comments

Hello, Firstly, the code worked very well, thank you for that. I have some problems. I'd appreciate it if you could help.

1. Problem - I want to get path at the request stage. Define two separate thread pools and i want to add requests to the thread pool by paths. I can get path, but the request is terminated. My sample code is below.

def __init__(self, threads=None, *args, **kwargs):
    WSGIServer.__init__(self, *args, **kwargs)
    self.threads = threads
    self.pool = multiprocessing.pool.ThreadPool(2)
    self.pool2 = multiprocessing.pool.ThreadPool(2)

def process_request_thread(self, r, client_address):
    try:
        self.finish_request(r, client_address)
        self.shutdown_request(r) 
    except:
        self.handle_error(r, client_address)
        self.shutdown_request(r)

def process_request(self, r, client_address):
    path = str(r.makefile('rb', -1).readline(65537), 'iso-8859-1').rstrip('\r\n').split()[1]
    if path == '/Add' or path == '/Delete':
        self.pool.apply_async(self.process_request_thread, args=(r, client_address))
    else:
        self.pool2.apply_async(self.process_request_thread, args=(r, client_address))

2. Problem - I want to set different timeout value of request by paths. 3. Answer - I setted 4 threads. I run code. Result 7 threads opened. Why?

Thanks.

gokh4n avatar Aug 02 '19 14:08 gokh4n