Copy callbacks instead of slice for event dispatch (#109711)
We established copy is faster in https://github.com/home-assistant/core/pull/108428#discussion_r1466932262pull/109731/head
parent
8df305c881
commit
6f28d79651
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue