From a190184b0ce47617c6a029b350014a4ba8088103 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 10 Jan 2019 18:14:41 +0100 Subject: [PATCH] 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 --- platypush/plugins/music/snapcast.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/platypush/plugins/music/snapcast.py b/platypush/plugins/music/snapcast.py index 6c368bf673..973e84c8c7 100644 --- a/platypush/plugins/music/snapcast.py +++ b/platypush/plugins/music/snapcast.py @@ -565,11 +565,11 @@ class MusicSnapcastPlugin(Plugin): """ backend_hosts = self.get_backend_hosts().output + playing_hosts = {} def _worker(host, port): if exclude_local and (host == 'localhost' or host == Config.get('device_id')): - del backend_hosts[host] return server_status = self.status(host=host, port=port).output @@ -577,23 +577,22 @@ class MusicSnapcastPlugin(Plugin): client=Config.get('device_id')).output if client_status.get('config', {}).get('volume', {}).get('muted'): - del backend_hosts[host] return group = [g for g in server_status.get('groups', {}) if g.get('id') == client_status.get('group_id')].pop(0) if group.get('muted'): - del backend_hosts[host] return stream = [s for s in server_status.get('streams') if s.get('id') == group.get('stream_id')].pop(0) if stream.get('status') != 'playing': - del backend_hosts[host] return + playing_hosts[host] = port + workers = [] for host, port in backend_hosts.items(): @@ -605,7 +604,7 @@ class MusicSnapcastPlugin(Plugin): w = workers.pop() w.join() - return {'hosts': backend_hosts} + return {'hosts': playing_hosts} # vim:sw=4:ts=4:et: