from asgiref.sync import async_to_sync async def func(args): pass async_to_sync(func)(args)
Here is what the above code is Doing:
1. The async_to_sync function is a decorator that takes an async function and returns a sync function.
2. The sync function is called with the same arguments as the async function.
3. The sync function calls the async function with the same arguments.
4. The async function is executed in a separate thread.
5. The async function returns a future.
6. The sync function blocks until the future is done.
7. The sync function returns the result of the async function.