Acquire a lock while executing atomic DB commands.

This should prevent it from saving the database while there's a command executing.
Though a faster way would be to somehow force the GIL to stay acquired
while executing these functions. Only release it for `select` maybe?
Not sure if there's a way to do that from Python code.