rawpy icon indicating copy to clipboard operation
rawpy copied to clipboard

Remove gil from C implementations to enable reading raw files in parallel threads

Open kmaddock opened this issue 3 years ago • 11 comments

Removing the gil allows loading raw files from multiple python threads in parallel to improve performance

kmaddock avatar Feb 01 '23 22:02 kmaddock

Cython in CI is failing, did you test this locally? Did you use a different cython version perhaps?

letmaik avatar Feb 02 '23 08:02 letmaik

I have been running it on Windows, I didn't do anything special with the Cython version!

It looks like I just need to move path.encode("UTF-8") out of the nogil block

kmaddock avatar Feb 02 '23 08:02 kmaddock

This also needs a test that tries to open/process multiple files in parallel.

letmaik avatar Feb 05 '23 19:02 letmaik

@kmaddock Are you still interested in working on this PR?

letmaik avatar May 09 '23 20:05 letmaik

Hi, I'm still interested in working on this PR, but I haven't had a chance to get back to it!

kmaddock avatar May 10 '23 04:05 kmaddock

@kmaddock There are still some things that need to be adapted for this to work, see the CI logs. Also, I noticed that the Windows and macOS builds use the thread-safe variant of libraw whereas on Linux the non-thread-safe variant is picked up via pkg-config, so this has to be changed as well.

letmaik avatar Oct 01 '23 10:10 letmaik

@kmaddock thanks for your hard work, this is really useful for making my image viewer more usable. Would you mind giving me access to your branch for this PR so I can add my changes please? I've finished it off at https://github.com/jontyrudman/rawpy/tree/nogil .

@letmaik my changes involve removing with nogil for open_file and altering setup.py to find libraw_r so it should use the threadsafe version on all platforms.

I ran your CI workflow on my fork and the only issue left is minor, I get a ModuleNotFoundError for distutils on the Python 3.12 macOS and Windows tests only.

EDIT: I've also started using it in my image viewer and nogil helps me a whole lot for my use case (still rendering Qt widgets while running postprocess() in a QThread without it freezing).

jontyrudman avatar Dec 30 '23 18:12 jontyrudman

I'll still need to write the test for it, of course.

jontyrudman avatar Dec 30 '23 18:12 jontyrudman

@jontyrudman Feel free to open a new PR for this. We can give credit to @kmaddock in the PR description / commit message.

letmaik avatar Jan 04 '24 22:01 letmaik

@jontyrudman How are you getting on? It's quite a useful feature!

letmaik avatar Jan 12 '24 09:01 letmaik

@letmaik I've been quite busy this week because I'm starting a new job next week, but I've got plans to work on this over the weekend.

jontyrudman avatar Jan 12 '24 09:01 jontyrudman