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.
This commit is contained in:
Richard Mitchell 2019-04-25 07:38:10 +02:00 committed by Paulus Schoutsen
parent de6fdb09f4
commit c216ac7260

View file

@ -172,12 +172,15 @@ def setup_plexserver(
# add devices with a session and no client (ex. PlexConnect Apple TV's) # add devices with a session and no client (ex. PlexConnect Apple TV's)
if config.get(CONF_INCLUDE_NON_CLIENTS): 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: if machine_identifier in available_client_ids:
# Avoid using session if already added as a device. # Avoid using session if already added as a device.
_LOGGER.debug("Skipping session, device exists: %s", _LOGGER.debug("Skipping session, device exists: %s",
machine_identifier) machine_identifier)
continue continue
if (machine_identifier not in plex_clients if (machine_identifier not in plex_clients
and machine_identifier is not None): and machine_identifier is not None):
new_client = PlexClient( new_client = PlexClient(