Locking is not going to help at all unless you have multiple processes or multiple threads.
When you use locking, you check if it is OK to perform an operation. If not you wait a while and check again, hoping that whatever is locking you out has finished and unlocked the resource. Without muli-tasking or multi-processing there is nobody who is going to unlock that resource. Your program will wait forever, blocking the code that might release the resource you are waiting for.
If you are running into problems with a single task program, it is likely you are not releasing resources when you should. For example, you should not make a bunch of changes to your database without committing. You should also not open a database connection and leave it open, assuming that nobody else has made any changes. Connect, query, make any changes you want, commit, close connection. This is best done using a context manager, forcing the closing when you leave the current context.
If multiple processes or tasks have access to shared, mutable resource you have to use some sort of locking mechanism. There really is no choicer.