Combine Flask async functions with Flask-Appbuilder?

31 views Asked by At

We have quite a big application built using AppBuilder. There is an extensive REST interface used by an external frontend.

Now we need to add file export functionality to the service. Files that are downloaded can be huge, and as AppBuilder is synchronous the downloads are blocking the service altogether.

Flask 2.x supports also async functions, however is it possible to have both async Flask functions and AppBuilder functions in the same application?

I added a quick test:

@app.route("/async_test")
async def async_test():
   return "123"

But when this route is accessed I get the error:

RuntimeError: You cannot use AsyncToSync in the same thread as an async event loop - just await the async function directly.

Documentation of ensure_sync() says "Override this method to change how the app runs async views." but I didn't find any examples.

If combining async routes with AppBuilder is not possible, what other options there might be to solve this?

0

There are 0 answers