Skip to content

Commit

Permalink
Merge pull request #725 from bigredfrog/audio_deactivate
Browse files Browse the repository at this point in the history
fix: protect against concurrent deactivate of audio
  • Loading branch information
shauneccles committed Feb 11, 2024
2 parents 91f4aba + c56fbb5 commit c493dae
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ledfx/effects/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def AUDIO_CONFIG_SCHEMA():

def __init__(self, ledfx, config):
self._ledfx = ledfx
self.lock = threading.Lock()
self.update_config(config)

def shutdown_event(e):
Expand Down Expand Up @@ -313,11 +314,12 @@ def open_audio_stream(device_idx):
open_audio_stream(default_device)

def deactivate(self):
if self._stream:
self._stream.stop()
self._stream.close()
self._stream = None
self._is_activated = False
with self.lock:
if self._stream:
self._stream.stop()
self._stream.close()
self._stream = None
self._is_activated = False
_LOGGER.info("Audio source closed.")

def subscribe(self, callback):
Expand Down

0 comments on commit c493dae

Please sign in to comment.