Database wide lock python decorator and context manager