Solved db locking with an RLock, added a more graceful exit