Skip to content

Commit

Permalink
guard readers.numpy PDAL functions with GIL acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jan 3, 2024
1 parent 82a52ac commit 99df2b9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pdal/io/NumpyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ PyArrayObject* load_npy_script(std::string const& source,
void NumpyReader::initialize()
{
plang::Environment::get();
plang::gil_scoped_acquire acquire;
m_numPoints = 0;
m_chunkCount = 0;
m_ndims = 0;
Expand Down Expand Up @@ -424,6 +425,7 @@ void NumpyReader::addDimensions(PointLayoutPtr layout)
{
using namespace Dimension;

plang::gil_scoped_acquire acquire;
wakeUpNumpyArray();
createFields(layout);

Expand Down Expand Up @@ -485,6 +487,7 @@ void NumpyReader::addDimensions(PointLayoutPtr layout)

void NumpyReader::ready(PointTableRef table)
{
plang::gil_scoped_acquire acquire;
plang::Environment::get()->set_stdout(log()->getLogStream());

// Set our iterators
Expand Down Expand Up @@ -528,6 +531,8 @@ bool NumpyReader::nextPoint()
// just advance by the stride.
if (--m_chunkCount == 0)
{
// Go grab the gil before we touch Python stuff again
plang::gil_scoped_acquire acquire;
// If we can't fetch the next ite
if (!m_iternext(m_iter))
return false;
Expand Down Expand Up @@ -653,6 +658,7 @@ bool NumpyReader::processOne(PointRef& point)

point_count_t NumpyReader::read(PointViewPtr view, point_count_t numToRead)
{
plang::gil_scoped_acquire acquire;
PointId idx = view->size();
point_count_t numRead(0);

Expand All @@ -670,8 +676,8 @@ point_count_t NumpyReader::read(PointViewPtr view, point_count_t numToRead)

void NumpyReader::done(PointTableRef)
{
plang::gil_scoped_acquire acquire;
// Dereference everything we're using

if (m_iter)
NpyIter_Deallocate(m_iter);

Expand Down

0 comments on commit 99df2b9

Please sign in to comment.