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

support of async views #192

Open
yan-hic opened this issue Jun 15, 2022 · 3 comments
Open

support of async views #192

yan-hic opened this issue Jun 15, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@yan-hic
Copy link

yan-hic commented Jun 15, 2022

Similarly to Flask, the framework should support async function for a view - see https://flask.palletsprojects.com/en/2.1.x/async-await/
Under the hood, Flask executes asyncio.run() and returns the resulting value to the client.

When trying to define the view function with async, one gets TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a coroutine.

Workaround is simply to create a "regular" sync function that executes (asyncio.run()) a separate async function but it could be simpler and match Flask functionality.

Our use case: use Google Cloud Functions from BigQuery Remote Function to call external APIs concurrently (using aiohttp).

@josephlewis42 josephlewis42 added the enhancement New feature or request label Feb 24, 2023
@mikemykhaylov
Copy link

Is there any progress on this? I have a different use case (downloading and sending a file over the network, both function calls as coroutines), and a native support for async would be much appreciated compared to the asyncio.run() workaround.

@yan-hic
Copy link
Author

yan-hic commented Apr 11, 2023

Have a look at unsync library. We use it all the time now.

@xSAVIKx
Copy link

xSAVIKx commented Aug 30, 2023

I believe this is somewhat blocked by the threads worker of Gunicorn used under the hood. And Gunicorn itself has had issues with async workers for a long time, but the latest v21 release should unblock a lot of different things.

IMO this one is blocked by #270 and #241

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

No branches or pull requests

5 participants