def _optional_lock(self, needs_lock):
        """Context manager for optionally acquiring a lock."""
        if needs_lock:
            with self._lock:
                yield
        else:
            yield
Context manager for optionally acquiring a lock.
xarray/backends/file_manager.py