Skip to content

Commit f11c949

Browse files
Merge pull request #384 from Jgunde/patch-1
Release Python Global Interpreter Lock During Detection
2 parents 3676389 + 697ff80 commit f11c949

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

apriltag_pywrap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ static PyObject* apriltag_detect(apriltag_py_t* self,
243243
.stride = strides[0],
244244
.buf = PyArray_DATA(image)};
245245

246-
zarray_t* detections = apriltag_detector_detect(self->td, &im);
246+
zarray_t *detections; // Declare detections variable outside of the GIL block
247+
Py_BEGIN_ALLOW_THREADS // Acquire the GIL before running detection
248+
detections = apriltag_detector_detect(self->td, &im);
249+
Py_END_ALLOW_THREADS // Release the GIL after detection completes
250+
247251
int N = zarray_size(detections);
248252

249253
if (N == 0 && errno == EAGAIN){

0 commit comments

Comments
 (0)