Locks are used to ensure exclusive access to a shared resource.
This statement might sound vague at first sight but this short gist outlines the working of asyncio.Lock
and how you can apply it on your use cases.
Locks solve the problem of having to deal with concurrent tasks accessing a resource that you don't want to be accessed concurrently.
In many cases, you might have a specific function that does something heavy in background or asynchronously. The problem here is that you don't want this function to be called concurrently or in other words, you don't want the task it is doing to happen concurrently. Instead, you want each of the task to happen once at a time.