Skip to content

Commit

Permalink
Clean up running spotify instances when removed from configuration (#564
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rtertiaer committed Dec 11, 2023
1 parent 2ca1da8 commit ace822f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions amplipi/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def disconnect(self):
try:
# must use terminate as kill() cannot be intercepted
self._cproc.terminate()
self._cproc.communicate(timeout=5)

except Exception as e:
print(f'PersistentStream disconnect error: {e}')
Expand Down Expand Up @@ -511,7 +512,6 @@ def __init__(self, name: str, disabled: bool = False, mock: bool = False):

self.connect_port: Optional[int] = None
self.mpris: Optional[MPRIS] = None
self.proc_pid: Optional[int] = None
self.supported_cmds = ['play', 'pause', 'next', 'prev']

def reconfig(self, **kwargs):
Expand All @@ -524,9 +524,6 @@ def reconfig(self, **kwargs):
if reconnect_needed and self.is_activated():
self.reactivate()

def __del__(self):
self.disconnect()

def is_persistent(self):
return True

Expand Down Expand Up @@ -572,9 +569,11 @@ def _activate(self, vsrc: int):

def _deactivate(self):
try:
self.proc.kill()
except Exception:
pass
self.proc.terminate()
outs, errs = self.proc.communicate(timeout=3)
except Exception as e:
print(f"failed to terminate spotify stream: {e}")
kouts, kerrs = self.proc.kill()
try:
del self.mpris
except Exception:
Expand Down

0 comments on commit ace822f

Please sign in to comment.