Database access locking for scaling to multiple concurrent instances on a single host

* Added `DBLock` context manager to use on code blocks that require synchronized database access
* Applied context manager to relevant blocks

resolves #110