Run synchronous functions asynchronously
Running your bound, synchronous functions asynchronously can be an easy way to make your application responsive and scale to more users.
Asyncify
This example will show how to make your app responsive by running a sync, cpu bound function asynchronously. We will be using asyncer by Tiangolo. You can install the package via pip install asyncer
.
Your browser does not support the video tag.
Without asyncify
the app would have been unresponsive for 5-10 seconds while loading.
asyncify
works well for IO bound functions as well as for CPU bound functions that releases the GIL.
Dask
If you run many cpu bound functions you may consider offloading your functions asynchronously to an external compute engine like Dask. See our Dask how-to Guide.