pytdb: Check if the database is closed before we touch it