Answer the question
In order to leave comments, you need to log in
What is the best way to send HTTP requests to a third-party service in Django?
Hello!
I need to send a GET request to a third-party service through dzhang's views.
At first glance, you can simply do:
r = requests.get("http://example.ru")
print r.status
Answer the question
In order to leave comments, you need to log in
Unlike Alexei Bukin, you understand almost correctly. Python is single-threaded by default. And if you perform a blocking operation, and all socket operations are blocking, then the entire thread will be blocked. As a rule, the server (uwsgi, gunicorn) launches several threads of execution ( workers ) between which user requests are shared, but nevertheless, in your case, each of them may hang for the duration of the operation on the socket.
There are two ways to deal with this, the first is to execute them in other processes using the same cellery. True, then you have to tinker in order to give the result to the client.
The second is to try to use gevent which will provide the ability to work with sockets asynchronously. You need to dig towards the gevent mode of the uwsgi daemon.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question