Skip to content

Commit f698ae3

Browse files
authored
fix(python): IBA.demosaic had GIL release in wrong spot (#4777)
Only symptomatic on debug builds, but I was seeing exceptions from pybind11 about bad GIL release. I traced it to the recent implementations of demosaic. Apparently it's not safe to release the GIL until AFTER the call to py_to_stdvector. Which makes sense when you think about it -- we need the lock whenever we are interacting directly with Python calls or data structures (such as what py_to_stdvector is doing), but we release it when we're done with the python and only calling OIIO internals (such as IBA::demosaic() itself). Signed-off-by: Larry Gritz <[email protected]>
1 parent 54d012e commit f698ae3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/python/py_imagebufalgo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,9 +2397,9 @@ IBA_demosaic_ret(const ImageBuf& src, const std::string& pattern = "",
23972397
py::object white_balance = py::none(), ROI roi = ROI::All(),
23982398
int nthreads = 0)
23992399
{
2400-
py::gil_scoped_release gil;
24012400
std::vector<float> wb;
24022401
py_to_stdvector(wb, white_balance);
2402+
py::gil_scoped_release gil;
24032403
return ImageBufAlgo::demosaic(src,
24042404
{ { "pattern", pattern },
24052405
{ "algorithm", algorithm },
@@ -2416,9 +2416,9 @@ IBA_demosaic(ImageBuf& dst, const ImageBuf& src,
24162416
py::object white_balance = py::none(), ROI roi = ROI::All(),
24172417
int nthreads = 0)
24182418
{
2419-
py::gil_scoped_release gil;
24202419
std::vector<float> wb;
24212420
py_to_stdvector(wb, white_balance);
2421+
py::gil_scoped_release gil;
24222422
return ImageBufAlgo::demosaic(dst, src,
24232423
{ { "pattern", pattern },
24242424
{ "algorithm", algorithm },

0 commit comments

Comments
 (0)