Skip to content

support of async views #192

Open
Open

Description

@yan-hic

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).

Activity

  1. mikemykhaylov commented on Apr 10, 2023

    @mikemykhaylov

    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.

  2. yan-hic commented on Apr 11, 2023

    @yan-hic
    Author

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

  3. xSAVIKx commented on Aug 30, 2023

    @xSAVIKx

    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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions