Full thread safety in Database.py