mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-09-02 11:22:41 +01:00
framework, tests: Correct signal disconnection
While the Louie system operated on weakrefs for the callback functions, the priority list wrapper did not. This difference led to weakrefs to callback functions being compared to strong references in list element operations within Louie's disconnect method, so that handler methods were not disconnected from signals. Converting the receiver to a weakref then allowed Louie to operate as normal, which may include deleting and re-appending the handler method to the receivers list. As ``append`` is a dummy method that allows the priority list implementation, the handler method is then never added back to the list of connected functions, so we must ``add`` it after ``connect`` is called. Also included is a testcase to confirm the proper disconnection of signals.
This commit is contained in:
committed by
Marc Bonnici
parent
3f5a31de96
commit
7cf5fbd8af
@@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
"""
|
||||
This module wraps louie signalling mechanism. It relies on modified version of loiue
|
||||
This module wraps louie signalling mechanism. It relies on modified version of louie
|
||||
that has prioritization added to handler invocation.
|
||||
|
||||
"""
|
||||
@@ -23,8 +23,9 @@ import sys
|
||||
import logging
|
||||
from contextlib import contextmanager
|
||||
|
||||
from louie import dispatcher, saferef # pylint: disable=wrong-import-order
|
||||
from louie.dispatcher import _remove_receiver
|
||||
import wrapt
|
||||
from louie import dispatcher # pylint: disable=wrong-import-order
|
||||
|
||||
from wa.utils.types import prioritylist, enum
|
||||
|
||||
@@ -242,8 +243,8 @@ def connect(handler, signal, sender=dispatcher.Any, priority=0):
|
||||
receivers = signals[signal]
|
||||
else:
|
||||
receivers = signals[signal] = _prioritylist_wrapper()
|
||||
receivers.add(handler, priority)
|
||||
dispatcher.connect(handler, signal, sender)
|
||||
receivers.add(saferef.safe_ref(handler, on_delete=_remove_receiver), priority)
|
||||
|
||||
|
||||
def disconnect(handler, signal, sender=dispatcher.Any):
|
||||
@@ -268,7 +269,7 @@ def send(signal, sender=dispatcher.Anonymous, *args, **kwargs):
|
||||
"""
|
||||
Sends a signal, causing connected handlers to be invoked.
|
||||
|
||||
Paramters:
|
||||
Parameters:
|
||||
|
||||
:signal: Signal to be sent. This must be an instance of :class:`wa.core.signal.Signal`
|
||||
or its subclasses.
|
||||
|
Reference in New Issue
Block a user