You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Reacted by Amit Moryossef, Keaton Cross, SilicalNZ, Taylor Richberger, Michael Mykhaylov, Stephan Thiel, Jonathan Ballet, Yurii Serhiichuk, Aaron Abbott, Devin Stein and 1 more
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.
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.
Activity
mikemykhaylov commentedon Apr 10, 2023
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
asyncwould be much appreciated compared to theasyncio.run()workaround.yan-hic commentedon Apr 11, 2023
Have a look at
unsynclibrary. We use it all the time now.xSAVIKx commentedon 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