Skip to content

Commit

Permalink
Cleanup GIL stuff (#157)
Browse files Browse the repository at this point in the history
* executeStream already does GIL release, we don't need to do it. pybind11 does GIL acquire with every method call so we don't need to be doing that either

* wip

* put back acq

* wip

* wip2

* wip3

* wip4

* wip4

* comment why we need gil_scope_acquire for getExecutor
  • Loading branch information
hobu committed Jan 5, 2024
1 parent dd75a38 commit dc8b1b5
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pdal/libpdalpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace pdal {
};

std::vector<py::dict> getDrivers() {
py::gil_scoped_acquire acquire;
std::vector<py::dict> drivers;

pdal::StageFactory f(false);
Expand Down Expand Up @@ -59,7 +58,6 @@ namespace pdal {
};

py::object getOptions() {
py::gil_scoped_acquire acquire;
py::object json = py::module_::import("json");
py::dict stageOptions;

Expand Down Expand Up @@ -94,7 +92,6 @@ 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 @@ -112,13 +109,11 @@ 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 @@ -142,7 +137,6 @@ namespace pdal {
}

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

std::stringstream strm;
Expand Down Expand Up @@ -190,7 +184,6 @@ namespace pdal {
}

void setInputs(std::vector<py::array> ndarrays) {
py::gil_scoped_acquire acquire;
_inputs.clear();
for (const auto& ndarray: ndarrays) {
PyArrayObject* ndarray_ptr = (PyArrayObject*)ndarray.ptr();
Expand All @@ -209,7 +202,6 @@ namespace pdal {
std::string getSrsWKT2() { return getExecutor()->getSrsWKT2(); }

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

std::string response;
Expand Down Expand Up @@ -275,6 +267,10 @@ namespace pdal {
void delExecutor() { _executor.reset(); }

PipelineExecutor* getExecutor() {
// We need to acquire the GIL before we create the executor
// because this method does Python init stuff but pybind11 doesn't
// automatically encapsulate it with a gil_scoped_acquire like it
// does for all of the other methods it knows about
py::gil_scoped_acquire acquire;
if (!_executor)
_executor.reset(new PipelineExecutor(getJson(), _inputs, _loglevel));
Expand Down

0 comments on commit dc8b1b5

Please sign in to comment.