Python decorator for atomicity