Skip to content

Commit

Permalink
Fix response iterator memory leak (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabrizian committed Sep 26, 2023
1 parent 238e0d0 commit b136bf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/pb_response_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ResponseIterator::Next()
}
}

py::iterator
void
ResponseIterator::Iter()
{
if (is_finished_) {
Expand All @@ -111,8 +111,6 @@ ResponseIterator::Iter()
idx_ = 0;
}
}

return py::cast(*this);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/pb_response_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ResponseIterator {
~ResponseIterator();

std::shared_ptr<InferResponse> Next();
py::iterator Iter();
void Iter();
void EnqueueResponse(std::shared_ptr<InferResponse> infer_response);
void* Id();
void Clear();
Expand Down
7 changes: 6 additions & 1 deletion src/pb_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,12 @@ PYBIND11_EMBEDDED_MODULE(c_python_backend_utils, module)
py::class_<ResponseIterator, std::shared_ptr<ResponseIterator>>(
module, "ResponseIterator")
.def(py::init<const std::shared_ptr<InferResponse>&>())
.def("__iter__", &ResponseIterator::Iter, py::keep_alive<0, 1>())
.def(
"__iter__",
[](ResponseIterator& it) -> ResponseIterator& {
it.Iter();
return it;
})
.def("__next__", &ResponseIterator::Next);

py::class_<Logger> logger(module, "Logger");
Expand Down

0 comments on commit b136bf3

Please sign in to comment.