Python web server: how to serve requests asynchronously

I need to create python middleware that will do the following:

a) Accept HTTP receive / send requests from multiple clients.

b) Modify and send these requests to the remote application on the backend (via socket communication). I have no control over this remote application.

c) Receive processed results from the backend application and return these results back to requesting clients.

Clients now expect a synchronous request / response script. But the backend application does not return results synchronously. That is, some queries take much longer than others. Hence,

Client 1: send an HTTP request C1 → receive a response R1

Client 2: send HTTP request C2 -> get R2 response

Client 3: send HTTP request C3 -> get R3 response

Python middleware gets them in some order: C2, C3, C1. Sends them in this order to the backend (as messages other than http). The backend responds with the results in the mixed order of R1, R3, R2. The Python binding tool should pack these responses back into the HTTP response objects and send the response back to the appropriate client.

Is there any code example for programming this behavior. There seems to be something like 20 different web frameworks for python, and I'm confused about which one is best for this scenario (would prefer something as light as possible ... I would find Django too heavy .. I tried the bottle, but I'm not sure how to program that for this scenario).

================================================= =

( ): . ( , ). - . {request_id: ip_address}, , HTTP . , , .

+3
2

. asyncore. : , . , , . http , . uwsgi, -, asyncore - . .

+3

:

. . . . : (-) , ? , - cgi script db , , HTTP- : clienttcpport?

- ? , .

( dict threading.Lock). (). , , , .

UPDATE: - - .

+2

Source: https://habr.com/ru/post/1791702/


All Articles