Skip to content

Commit

Permalink
release the Python GIL for long(er) running processes like execute an…
Browse files Browse the repository at this point in the history
…d preview
  • Loading branch information
hobu committed Jan 1, 2024
1 parent dfdc448 commit 451b8e0
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions pdal/libpdalpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace pdal {
};

std::vector<py::dict> getDimensions() {
py::gil_scoped_acquire acquire;
py::object np = py::module_::import("numpy");
py::object dtype = np.attr("dtype");
std::vector<py::dict> dims;
Expand All @@ -111,11 +112,13 @@ namespace pdal {

std::string getReaderDriver(std::filesystem::path const& p)
{
py::gil_scoped_acquire acquire;
return StageFactory::inferReaderDriver(p.string());
}

std::string getWriterDriver(std::filesystem::path const& p)
{
py::gil_scoped_acquire acquire;
return StageFactory::inferWriterDriver(p.string());
}

Expand All @@ -139,6 +142,7 @@ namespace pdal {
}

py::object getMetadata() {
py::gil_scoped_acquire acquire;
py::object json = py::module_::import("json");

std::stringstream strm;
Expand All @@ -160,10 +164,23 @@ namespace pdal {

class Pipeline {
public:
point_count_t execute() { return getExecutor()->execute(); }
point_count_t execute() {
point_count_t response(0);
{
py::gil_scoped_release release;
response = getExecutor()->execute();
}
return response;

}

point_count_t executeStream(point_count_t streamLimit) {
return getExecutor()->executeStream(streamLimit);
point_count_t response(0);
{
py::gil_scoped_release release;
response = getExecutor()->executeStream(streamLimit);
}
return response;
}

std::unique_ptr<PipelineIterator> iterator(int chunk_size, int prefetch) {
Expand Down Expand Up @@ -194,7 +211,12 @@ namespace pdal {
py::gil_scoped_acquire acquire;
py::object json = py::module_::import("json");

py::bytes pybytes(getExecutor()->getQuickInfo());
std::string response;
{
py::gil_scoped_release release;
response = getExecutor()->getQuickInfo();
}
py::bytes pybytes(response);

py::str pystring ( pybytes.attr("decode")("utf-8", "ignore"));
pystring.attr("strip");
Expand Down

0 comments on commit 451b8e0

Please sign in to comment.