From 136534154950002ada7766cf6fc497af3306638a Mon Sep 17 00:00:00 2001 From: Lewis Cowles Date: Sat, 6 Dec 2025 16:47:17 +0000 Subject: [PATCH] fix: example_animated I use this for my own streamdeck; this fixes an issue where each animation thread attempts to run, even once the streamdeck has been closed. I thought about changing the library, but actually I am sure it is the structure of this example --- src/example_animated.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/example_animated.py b/src/example_animated.py index 462ba282..fefb24c4 100644 --- a/src/example_animated.py +++ b/src/example_animated.py @@ -28,6 +28,7 @@ # Animation frames per second to attempt to display on the StreamDeck devices. FRAMES_PER_SECOND = 30 +closed_event = threading.Event() # Loads in a source image, extracts out the individual animation frames (if @@ -60,12 +61,14 @@ def create_animation_frames(deck, image_filename): def key_change_callback(deck, key, state): # Use a scoped-with on the deck to ensure we're the only thread using it # right now. - with deck: - # Reset deck, clearing all button images. - deck.reset() + if state: + closed_event.set() + with deck: + # Reset deck, clearing all button images. + deck.reset() - # Close deck handle, terminating internal worker threads. - deck.close() + # Close deck handle, terminating internal worker threads. + deck.close() if __name__ == "__main__": @@ -124,7 +127,7 @@ def animate(fps): # Periodic loop that will render every frame at the set FPS until # the StreamDeck device we're using is closed. - while deck.is_open(): + while not closed_event.is_set() and deck.is_open(): try: # Use a scoped-with on the deck to ensure we're the only # thread using it right now.