Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gunicorn Django gevent worker asyncio code causes SynchronousOnlyOperation error #3053

Open
bioworkflows opened this issue Aug 11, 2023 · 0 comments

Comments

@bioworkflows
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant