diff --git a/src/wrappers/python/PyOpenEXR.cpp b/src/wrappers/python/PyOpenEXR.cpp index 2e358446c..56708d4e8 100644 --- a/src/wrappers/python/PyOpenEXR.cpp +++ b/src/wrappers/python/PyOpenEXR.cpp @@ -425,17 +425,29 @@ PyFile::readPartsFromOpenInput(bool separate_channels) // auto type = header.type(); - if (type == SCANLINEIMAGE || type == TILEDIMAGE) + try { - P.readPixels(*_inputFile, header.channels(), shape, rgbaChannels, dw, separate_channels); + if (type == SCANLINEIMAGE || type == TILEDIMAGE) + { + P.readPixels(*_inputFile, header.channels(), shape, rgbaChannels, dw, separate_channels); + } + else if (type == DEEPSCANLINE || type == DEEPTILE) + { + P.readDeepPixels(*_inputFile, type, header.channels(), shape, rgbaChannels, dw, separate_channels); + } + parts.append(py::cast(PyPart(P))); } - else if (type == DEEPSCANLINE || type == DEEPTILE) + catch (const std::exception& e) { - P.readDeepPixels(*_inputFile, type, header.channels(), shape, rgbaChannels, dw, separate_channels); + // Log the error and skip appending this part + py::print("Warning: Exception raised reading pixel data for part", part_index, "-", e.what()); } } - - parts.append(py::cast(PyPart(P))); + else + { + // If only reading the header, always append this part + parts.append(py::cast(PyPart(P))); + } } // for parts }