Skip to content

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