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.
pull/84133/head
Martin Krizek 1 month ago committed by GitHub
parent 4f6276d72d
commit 42e2f09b97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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 = []

Loading…
Cancel
Save