gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

gunicorn + Django + gevent worker + asyncio code causes SynchronousOnlyOperation error

Open bioworkflows opened this issue 2 years ago • 2 comments

As explained in this stack overflow post , we are running a Django server on gunicorn with gevent workers. The entire website is running in sync mode but we made the mistake (?) of rewriting part of our view code using asyncio.

async def utility_func(urls):
    # these use httpx async httpx request    
    await asyncio.gather(download_from_urls)

class MyView(generic.edit.FormView)
    def form_valid(self, form):
        asyncio.run(utility_func(form.cleaned_data['urls']))

The view function is 10+ times faster, but other parts of the website throws SynchronousOnlyOperation exceptions when the asyncio code is running, likely because they are executed in the async context created by asyncio.run. Can anyone explain to me what is happening here and how I should resolve the issue?

bioworkflows avatar Aug 11 '23 16:08 bioworkflows