From c216ac72608e8a9943eab38ea716f9d9d5a8421c Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Thu, 25 Apr 2019 07:38:10 +0200 Subject: [PATCH] Fix race condition. (#21244) If the updater is running at the same time, this can result in this dict changing size during iteration, which Python does not like. --- homeassistant/components/plex/media_player.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/plex/media_player.py b/homeassistant/components/plex/media_player.py index 4cb4204f274..4a65808e049 100644 --- a/homeassistant/components/plex/media_player.py +++ b/homeassistant/components/plex/media_player.py @@ -172,12 +172,15 @@ def setup_plexserver( # add devices with a session and no client (ex. PlexConnect Apple TV's) if config.get(CONF_INCLUDE_NON_CLIENTS): - for machine_identifier, (session, player) in plex_sessions.items(): + # To avoid errors when plex sessions created during iteration + sessions = list(plex_sessions.items()) + for machine_identifier, (session, player) in sessions: if machine_identifier in available_client_ids: # Avoid using session if already added as a device. _LOGGER.debug("Skipping session, device exists: %s", machine_identifier) continue + if (machine_identifier not in plex_clients and machine_identifier is not None): new_client = PlexClient(