How to send HTTP requests for multiple clients without blocking? #2103
etale-cohomology
started this conversation in
General
Replies: 1 comment 1 reply
-
Not familiar with this geventhttpclient package that you are using. For any non-gevent client you will need to monkey patch the standard library. Have you tried that? https://uwsgi-docs.readthedocs.io/en/latest/Gevent.html#monkey-patching |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can I send HTTP requests asynchronously for multiple clients, in non-blocking manner? (Ie. how to "yield" HTTP requests?)
I have a Flask websocket route that sends an HTTP request to an external API.
As the HTTP request is returning data, I
emit()
the data back to the client (the HTTP request takes a long time; say, about a minute).While the HTTP request is returning data, the
emit/sleep
trick works well to "yield", and I can have multiple clients talking to a single uwsgi server and the requests appears to be served in parallel.However, the start of the HTTP request is still blocking.
First I tried
pycurl
,curl CLI
, and other libraries, but I guess they're not async-friendly, or "yield-able", so now I'm using geventhttpclient assuming it's better, but the initial HTTP request is still blocking, even withgevent.sleep(0)
.The result is that, if I have 2 websocket clients (client
A
and clientB
), and clientA
sends a request, and then clientB
sends a request whileuwsgi
is still returning the response to clientA
, clientA
's response halt/blocks when Flask starts clientB
's external HTTP request and then resumes (and this is a very noticeable hiccup).The external HTTP request looks something like:
Following this I'm running uwsgi like so:
Beta Was this translation helpful? Give feedback.
All reactions