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

Add initializer and initargs to the execute function #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Era-Dorta
Copy link

@Era-Dorta Era-Dorta commented Jul 10, 2024

This PR exposes the initializer and initargs arguments of the ThreadPoolExecutor method. One useful example of this is integrating with tqdm to get a progress bar, as was requested in this issue #13.

Here is a minimal example on how to do that, which I'm happy to turn into a PR if this gets merged.

from multiprocessing import Value
from multiprocessing.sharedctypes import Synchronized

...
# ffmpeg command to turn images into a video
...

with tqdm(total=frame_idx) as pbar:
    prev_frame_idx_shared = Value("i", 0)

    def thread_initializer(args: Synchronized) -> None:
        global prev_frame_idx_shared
        prev_frame_idx_shared = args

    @ffmpeg.on("progress")
    def on_progress(progress: Progress) -> None:
        pbar.update(progress.frame - prev_frame_idx_shared.value)
        prev_frame_idx_shared.value = progress.frame

    ffmpeg.execute(initializer=thread_initializer, initargs=(prev_frame_idx_shared,))

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.

1 participant