Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cont'd) Remove gil from C implementations to enable reading raw files in parallel threads #220

Merged
merged 4 commits into from
May 6, 2024

Conversation

jontyrudman
Copy link
Contributor

Apologies for the radio silence; I do intend to get this done, I just need to work out the best way of testing that two threads have successfully run in parallel.

This work was started by kmaddock, new PR made because they were unresponsive.

@jontyrudman
Copy link
Contributor Author

Just rebased to fix those CI issues for Python 3.12 on macos and windows.

Struggling to find a concrete way to test that the nogil stuff is working - I know it does because I've seen the benefits in my application but I can't get parallel imread and postprocess to look tangibly different from ones in series in the test func I'm working on right now.

@EmersonDove
Copy link

This worked super well for me first try, this code below now runs correctly where the main thread now correctly prints 10 times a second while the reading thread runs:

import threading
import time
from pathlib import Path

import rawpy
from PIL import Image as PIL_Im


def process_rawpy(path):
    with rawpy.imread(str(path)) as raw:
        rgb = raw.postprocess(use_camera_wb=True)

    return rgb


def open_image(path: str) -> PIL_Im:
    while True:
        if isinstance(path, str):
            path = Path(path)

        try:
            result = process_rawpy(path)
        except Exception as e:
            print(f'Failed to open raw image {path} with rawpy, falling back to Pillow: {e}')


if __name__ == "__main__":
    threading.Thread(target=open_image, args=('/path/to/arw',)).start()

    while True:
        print("Main Loop")
        time.sleep(0.1)

Would be great to get this merged, going to make my own pypi distribution for it for our own usage so having it in mainline would be great.

@letmaik
Copy link
Owner

letmaik commented May 6, 2024

OK, let's merge this, I think we got enough evidence that it works.

@letmaik letmaik merged commit 23d8cd0 into letmaik:main May 6, 2024
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants