From 6f28d79651524f9a46a70274550140c05a4a5e64 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 5 Feb 2024 10:07:21 -0600 Subject: [PATCH] Copy callbacks instead of slice for event dispatch (#109711) We established copy is faster in https://github.com/home-assistant/core/pull/108428#discussion_r1466932262 --- homeassistant/helpers/event.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index d3f4144a293..ea80591a989 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -291,7 +291,7 @@ def _async_dispatch_entity_id_event( """Dispatch to listeners.""" if not (callbacks_list := callbacks.get(event.data["entity_id"])): return - for job in callbacks_list[:]: + for job in callbacks_list.copy(): try: hass.async_run_hass_job(job, event) except Exception: # pylint: disable=broad-except @@ -428,7 +428,7 @@ def _async_dispatch_old_entity_id_or_entity_id_event( ) ): return - for job in callbacks_list[:]: + for job in callbacks_list.copy(): try: hass.async_run_hass_job(job, event) except Exception: # pylint: disable=broad-except @@ -499,7 +499,7 @@ def _async_dispatch_device_id_event( """Dispatch to listeners.""" if not (callbacks_list := callbacks.get(event.data["device_id"])): return - for job in callbacks_list[:]: + for job in callbacks_list.copy(): try: hass.async_run_hass_job(job, event) except Exception: # pylint: disable=broad-except