Stop a thread of a given name.
1def pick_color(): 2 global color 3 color = py5.random_int(255), py5.random_int(255), py5.random_int(255) 4 5 6def setup(): 7 py5.launch_repeating_thread(pick_color, name='pick_color', time_delay=1) 8 9 10def draw(): 11 py5.background(*color) 12 if py5.frame_count == 500: 13 py5.stop_thread('pick_color')
Stop a thread of a given name. The
wait parameter determines if the method call will return right away or wait for the thread to exit.
This won’t do anything useful if the thread was launched with either launch_thread() or launch_promise_thread() and the
wait parameter is
False. Non-repeating threads are executed once and will stop when they complete execution. Setting the
wait parameter to
True will merely block until the thread exits on its own. Killing off a running thread in Python is complicated and py5 cannot do that for you. If you want a thread to perform some action repeatedly and be interuptable, use launch_repeating_thread() instead.
stop_thread(name: str, wait: bool = False) -> None
name: str - name of thread
wait: bool = False - wait for thread to exit before returning
Updated on September 11, 2021 16:51:34pm UTC