diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2024-10-17 08:33:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 08:33:39 +0200 |
commit | 42e2f09b97c8b98ef4f069db3b49585245576354 (patch) | |
tree | ee6d712124ef79db36e369cdf2a093655b7e9899 /lib | |
parent | Remove configuration options that were moved to inventory plugins now that an... (diff) | |
download | ansible-42e2f09b97c8b98ef4f069db3b49585245576354.tar.xz ansible-42e2f09b97c8b98ef4f069db3b49585245576354.zip |
Faster host removal from a handler (#84091)
In ``Handler.notify_host`` we ensure that ``Handler.notified_hosts`` can contain
particular host at most once. Therefore for removing a host it should be
faster to use ``list.remove`` which removes the first item in the list,
as opposed to using list comprehension removing all such items.
Diffstat (limited to '')
-rw-r--r-- | lib/ansible/playbook/handler.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/ansible/playbook/handler.py b/lib/ansible/playbook/handler.py index c9cba6a6c3..125a9cddc7 100644 --- a/lib/ansible/playbook/handler.py +++ b/lib/ansible/playbook/handler.py @@ -17,6 +17,7 @@ from __future__ import annotations +from ansible.errors import AnsibleAssertionError from ansible.playbook.attribute import NonInheritableFieldAttribute from ansible.playbook.task import Task from ansible.module_utils.six import string_types @@ -59,7 +60,12 @@ class Handler(Task): return False def remove_host(self, host): - self.notified_hosts = [h for h in self.notified_hosts if h != host] + try: + self.notified_hosts.remove(host) + except ValueError: + raise AnsibleAssertionError( + f"Attempting to remove a notification on handler '{self}' for host '{host}' but it has not been notified." + ) def clear_hosts(self): self.notified_hosts = [] |