0

I have a Django project that runs by Daphne, one of my views needs to submit a http request externally using the requests package, unfortunately that package is not async compatible, so if the http call is blocked, the whole Daphne app hangs.

An simplified demo as below:

def view(request):
    # this call will get timed out
    data = requests.get('https://blocked') 
    ...
    return Response(...)

I did some quick search and couldn't find any quick answers. One possibility is to serve these views via Uwsgi, apart from this approach, are there any other quick wins?

Use aiohttp? Problem is that http call is done inside an external package, that I means I will have to modify that external package to use aiohttp

James Lin
  • 25,028
  • 36
  • 133
  • 233
  • Looks like this is the answer https://stackoverflow.com/questions/43241221/how-can-i-wrap-a-synchronous-function-in-an-async-coroutine – James Lin Jan 25 '23 at 22:57

0 Answers0