spotify / pedalboard

🎛 🔊 A Python library for audio.
https://spotify.github.io/pedalboard
GNU General Public License v3.0
4.96k stars 249 forks source link

Bug on Thread Example for `show_editor()` #324

Closed dschiller closed 1 month ago

dschiller commented 1 month ago

On page

https://spotify.github.io/pedalboard/reference/pedalboard.html#pedalboard.AudioUnitPlugin.show_editor

in the show_editor() Example it should be thread.start() not thread.run().

The Example:

import pedalboard
from threading import Event, Thread

plugin = pedalboard.load_plugin("../path-to-my-plugin-file")
close_window_event = Event()

def other_thread():
    # do something to determine when to close the window
    if should_close_window:
        close_window_event.set()

thread = Thread(target=other_thread)
thread.run()

# This will block until the other thread calls .set():
plugin.show_editor(close_window_event)

Corrected:

import pedalboard
from threading import Event, Thread

plugin = pedalboard.load_plugin("../path-to-my-plugin-file")
close_window_event = Event()

def other_thread():
    # do something to determine when to close the window
    if should_close_window:
        close_window_event.set()

thread = Thread(target=other_thread)
thread.start()

# This will block until the other thread calls .set():
plugin.show_editor(close_window_event)

The run() method is the entry point for the thread's activity, but calling it directly won't start the thread in a separate execution context.