Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Releasing the GIL during matrix image conversion

Open hmaarrfk opened this issue 3 years ago • 2 comments

I'm wondering how you would prefer to deal with small PRs that release the GIL.

I understand that those can cause a lot of churn due to unintended consequences when considering resource utilization.

What did you do?

I opened a PR without raising a dedicated issue first. https://github.com/python-pillow/Pillow/pull/6418

What did you expect to happen?

Given I had done some research on the history of releasing the GIL during computation, I figured that it was OK to open the pull request first. I was hoping for some comments or feedback, but I understand that different projects have different expectations on the order that things should happen.

What are your OS, Python and Pillow versions?

  • OS: Linux / Windows / OSX (All really!)
  • Python: 3.9
  • Pillow: 9.2.0

Code like this, will not be able to run in parallel on different threads.

import numpy as np
import PIL

image = np.zeros((1024, 1024, 3), dtype='uint8')
img = PIL.Image.fromarray(image)
matrix = (1, 2, 3, 4, 5, 6, 7, 8, 9)
final_image = np.asarray(
    img.convert(mode='RGB', matrix=matrix)
)

hmaarrfk avatar Aug 22 '22 19:08 hmaarrfk

It is not a problem to open pull requests without issues.

Your PR just hasn't been reviewed yet. I haven't reviewed it as I would like someone else with more C expertise to do so - you have mentioned 'unintended consequences', and that sounds like something I don't want to cause. As for the other core contributors, I can only say that we are doing this in our spare time.

radarhere avatar Aug 22 '22 22:08 radarhere

Yes, thanks for the PR! I'm in a similar position, not so familiar with the ins and outs of the GIL so would prefer someone else to review.

hugovk avatar Aug 23 '22 09:08 hugovk