Using async
await
makes the methods execute on the UI thread by default. I have ran into situations where performing await
on an expensive operation will result in the UI blocking (Like this post )
For example,
import asyncio
async def freeze_ui_5_seconds():
await asyncio.sleep(5)
await
ing this function on the UI thread will freeze the UI for 5 seconds. By utilizing await
the code will pause and not continue until the await
method has completed and a value can be returned. My question is, what does this achieve in the end if await
essentially makes the code synchronous, that is, we will not continue until the await
method has completed. Using await
in my mind just retracts the idea of asynchronous programming as we are now "pausing" and "not continuing" until this method has completed and will freeze the UI.