Skip to content

Commit dc8b1b5

Browse files
authored
Cleanup GIL stuff (#157)
* 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
1 parent dd75a38 commit dc8b1b5

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

pdal/libpdalpython.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace pdal {
3030
};
3131

3232
std::vector<py::dict> getDrivers() {
33-
py::gil_scoped_acquire acquire;
3433
std::vector<py::dict> drivers;
3534

3635
pdal::StageFactory f(false);
@@ -59,7 +58,6 @@ namespace pdal {
5958
};
6059

6160
py::object getOptions() {
62-
py::gil_scoped_acquire acquire;
6361
py::object json = py::module_::import("json");
6462
py::dict stageOptions;
6563

@@ -94,7 +92,6 @@ namespace pdal {
9492
};
9593

9694
std::vector<py::dict> getDimensions() {
97-
py::gil_scoped_acquire acquire;
9895
py::object np = py::module_::import("numpy");
9996
py::object dtype = np.attr("dtype");
10097
std::vector<py::dict> dims;
@@ -112,13 +109,11 @@ namespace pdal {
112109

113110
std::string getReaderDriver(std::filesystem::path const& p)
114111
{
115-
py::gil_scoped_acquire acquire;
116112
return StageFactory::inferReaderDriver(p.string());
117113
}
118114

119115
std::string getWriterDriver(std::filesystem::path const& p)
120116
{
121-
py::gil_scoped_acquire acquire;
122117
return StageFactory::inferWriterDriver(p.string());
123118
}
124119

@@ -142,7 +137,6 @@ namespace pdal {
142137
}
143138

144139
py::object getMetadata() {
145-
py::gil_scoped_acquire acquire;
146140
py::object json = py::module_::import("json");
147141

148142
std::stringstream strm;
@@ -190,7 +184,6 @@ namespace pdal {
190184
}
191185

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

211204
py::object getQuickInfo() {
212-
py::gil_scoped_acquire acquire;
213205
py::object json = py::module_::import("json");
214206

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

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

0 commit comments

Comments
 (0)