Release the GIL with the C++ execution stack is waiting for values to materialize.
@@ -101,27 +101,32 @@ PYBIND11_MODULE(executor_bindings, m) {
// PyExecutor trampoline goes here when ready
std::shared_ptr<Executor>>(m, "Executor")
.def("create_value", WithWrappedProtos(&Executor::CreateValue),
- py::arg("value_pb"), py::return_value_policy::move)
+ py::arg("value_pb"), py::return_value_policy::move,
+ py::call_guard<py::gil_scoped_release>())
.def("create_struct", WithWrappedProtos(&Executor::CreateStruct),
- py::return_value_policy::move)
+ py::return_value_policy::move,
+ py::call_guard<py::gil_scoped_release>())
.def("create_selection", WithWrappedProtos(&Executor::CreateSelection),
- py::return_value_policy::move)
+ py::return_value_policy::move,
+ py::call_guard<py::gil_scoped_release>())
.def("create_call", WithWrappedProtos(&Executor::CreateCall),
py::arg("function"),
// Allow `argument` to be `None`.
- py::arg("argument").none(true), py::return_value_policy::move)
+ py::arg("argument").none(true), py::return_value_policy::move,
+ py::call_guard<py::gil_scoped_release>())
.def("materialize",
WithWrappedProtos([](Executor& e, const ValueId& value_id)
-> absl::StatusOr<v0::Value> {
// Construct a new `v0::Value` to write to and return it to
// Python.
v0::Value value_pb;
- auto result = e.Materialize(value_id, &value_pb);
+ absl::Status result = e.Materialize(value_id, &value_pb);
if (!result.ok()) {
return result;
}
return value_pb;
- }));
+ }),
+ py::call_guard<py::gil_scoped_release>());
// Executor construction methods.
m.def("create_tensorflow_executor", &CreateTensorFlowExecutor,
