diff --git a/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc index f81ced7c86..65204417ed 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc @@ -50,14 +50,8 @@ Status PyFuncOp::Compute(const TensorRow &input, TensorRow *output) { } else { ret_py_obj = this->py_func_ptr_(); } - // Object is none if pyfunc timeout - if (ret_py_obj.is_none()) { - MS_LOG(INFO) << "Pyfunc execute time out"; - goto TimeoutError; - } if (output_type_ != DataType::DE_UNKNOWN) { RETURN_IF_NOT_OK(CastOutput(ret_py_obj, output)); - } else { if (py::isinstance(ret_py_obj)) { // In case of a n-m mapping, the return value will be a tuple of numpy arrays @@ -65,6 +59,10 @@ Status PyFuncOp::Compute(const TensorRow &input, TensorRow *output) { // Iterate over two containers simultaneously for memory copy for (size_t i = 0; i < ret_py_tuple.size(); i++) { py::object ret_py_ele = ret_py_tuple[i]; + // Object is none if pyfunc timeout + if (ret_py_ele.is_none()) { + goto TimeoutError; + } if (!py::isinstance(ret_py_ele)) { goto ShapeMisMatch; } diff --git a/mindspore/dataset/engine/datasets.py b/mindspore/dataset/engine/datasets.py index c43fe8e611..a392a8c1ed 100644 --- a/mindspore/dataset/engine/datasets.py +++ b/mindspore/dataset/engine/datasets.py @@ -1999,7 +1999,7 @@ class _PythonCallable: return result.get(60) except multiprocessing.TimeoutError: # Ensure c++ pyfunc threads exit normally if python sub-process is killed unnormally. - return None + return (None,) except KeyboardInterrupt: self.pool.terminate() self.pool.join() diff --git a/tests/ut/python/dataset/test_paddeddataset.py b/tests/ut/python/dataset/test_paddeddataset.py index 4dbc187447..afe52f3e85 100644 --- a/tests/ut/python/dataset/test_paddeddataset.py +++ b/tests/ut/python/dataset/test_paddeddataset.py @@ -504,7 +504,7 @@ def test_celeba_padded(): count = 0 for _ in data.create_dict_iterator(num_epochs=1, output_numpy=True): count = count + 1 - assert count == 2 + assert count == 4 if __name__ == '__main__':