Using an auxiliary map to keep track of the playing hosts to prevent errors when the items are removed by the worker threads while iterating them
This commit is contained in:
parent
2c8099e7ae
commit
a190184b0c
1 changed files with 4 additions and 5 deletions
|
@ -565,11 +565,11 @@ class MusicSnapcastPlugin(Plugin):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
backend_hosts = self.get_backend_hosts().output
|
backend_hosts = self.get_backend_hosts().output
|
||||||
|
playing_hosts = {}
|
||||||
|
|
||||||
def _worker(host, port):
|
def _worker(host, port):
|
||||||
if exclude_local and (host == 'localhost'
|
if exclude_local and (host == 'localhost'
|
||||||
or host == Config.get('device_id')):
|
or host == Config.get('device_id')):
|
||||||
del backend_hosts[host]
|
|
||||||
return
|
return
|
||||||
|
|
||||||
server_status = self.status(host=host, port=port).output
|
server_status = self.status(host=host, port=port).output
|
||||||
|
@ -577,23 +577,22 @@ class MusicSnapcastPlugin(Plugin):
|
||||||
client=Config.get('device_id')).output
|
client=Config.get('device_id')).output
|
||||||
|
|
||||||
if client_status.get('config', {}).get('volume', {}).get('muted'):
|
if client_status.get('config', {}).get('volume', {}).get('muted'):
|
||||||
del backend_hosts[host]
|
|
||||||
return
|
return
|
||||||
|
|
||||||
group = [g for g in server_status.get('groups', {})
|
group = [g for g in server_status.get('groups', {})
|
||||||
if g.get('id') == client_status.get('group_id')].pop(0)
|
if g.get('id') == client_status.get('group_id')].pop(0)
|
||||||
|
|
||||||
if group.get('muted'):
|
if group.get('muted'):
|
||||||
del backend_hosts[host]
|
|
||||||
return
|
return
|
||||||
|
|
||||||
stream = [s for s in server_status.get('streams')
|
stream = [s for s in server_status.get('streams')
|
||||||
if s.get('id') == group.get('stream_id')].pop(0)
|
if s.get('id') == group.get('stream_id')].pop(0)
|
||||||
|
|
||||||
if stream.get('status') != 'playing':
|
if stream.get('status') != 'playing':
|
||||||
del backend_hosts[host]
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
playing_hosts[host] = port
|
||||||
|
|
||||||
workers = []
|
workers = []
|
||||||
|
|
||||||
for host, port in backend_hosts.items():
|
for host, port in backend_hosts.items():
|
||||||
|
@ -605,7 +604,7 @@ class MusicSnapcastPlugin(Plugin):
|
||||||
w = workers.pop()
|
w = workers.pop()
|
||||||
w.join()
|
w.join()
|
||||||
|
|
||||||
return {'hosts': backend_hosts}
|
return {'hosts': playing_hosts}
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue