From 451b8e0fc85281e2fd8983890e34671e9cc7bfc6 Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Mon, 1 Jan 2024 16:20:34 -0600 Subject: [PATCH] release the Python GIL for long(er) running processes like execute and preview --- pdal/libpdalpython.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pdal/libpdalpython.cpp b/pdal/libpdalpython.cpp index 72b1d3a1..424bea76 100644 --- a/pdal/libpdalpython.cpp +++ b/pdal/libpdalpython.cpp @@ -94,6 +94,7 @@ namespace pdal { }; std::vector getDimensions() { + py::gil_scoped_acquire acquire; py::object np = py::module_::import("numpy"); py::object dtype = np.attr("dtype"); std::vector dims; @@ -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()); } @@ -139,6 +142,7 @@ namespace pdal { } py::object getMetadata() { + py::gil_scoped_acquire acquire; py::object json = py::module_::import("json"); std::stringstream strm; @@ -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 iterator(int chunk_size, int prefetch) { @@ -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");