Skip to content

Commit 99df2b9

Browse files
committed
guard readers.numpy PDAL functions with GIL acquisition
1 parent 82a52ac commit 99df2b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pdal/io/NumpyReader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ PyArrayObject* load_npy_script(std::string const& source,
198198
void NumpyReader::initialize()
199199
{
200200
plang::Environment::get();
201+
plang::gil_scoped_acquire acquire;
201202
m_numPoints = 0;
202203
m_chunkCount = 0;
203204
m_ndims = 0;
@@ -424,6 +425,7 @@ void NumpyReader::addDimensions(PointLayoutPtr layout)
424425
{
425426
using namespace Dimension;
426427

428+
plang::gil_scoped_acquire acquire;
427429
wakeUpNumpyArray();
428430
createFields(layout);
429431

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

486488
void NumpyReader::ready(PointTableRef table)
487489
{
490+
plang::gil_scoped_acquire acquire;
488491
plang::Environment::get()->set_stdout(log()->getLogStream());
489492

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

654659
point_count_t NumpyReader::read(PointViewPtr view, point_count_t numToRead)
655660
{
661+
plang::gil_scoped_acquire acquire;
656662
PointId idx = view->size();
657663
point_count_t numRead(0);
658664

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

671677
void NumpyReader::done(PointTableRef)
672678
{
679+
plang::gil_scoped_acquire acquire;
673680
// Dereference everything we're using
674-
675681
if (m_iter)
676682
NpyIter_Deallocate(m_iter);
677683

0 commit comments

Comments
 (0)