Skip to content

Commit 474a1e5

Browse files
committed
Merge branch 'tamuri/signal' into molaro/harvest-training-data-including-mni
Merge update on signal PR
2 parents 4fe8e1f + e617aa9 commit 474a1e5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/tlo/notify.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def dispatch(self, notification_key, data=None):
6060
for listener in self.listeners[notification_key]:
6161
listener(data)
6262

63+
def clear_listeners(self):
64+
"""
65+
Clear all registered listeners. Essential because the notifier is a global singleton.
66+
e.g. if you are running multiple tests or simulations in the same process.
67+
"""
68+
self.listeners.clear()
69+
6370

6471
# Create a global notifier instance
6572
notifier = Notifier()

src/tlo/simulation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
topologically_sort_modules,
2828
)
2929
from tlo.events import Event, IndividualScopeEventMixin
30+
from tlo.notify import notifier
3031
from tlo.progressbar import ProgressBar
3132

3233
if TYPE_CHECKING:
@@ -116,6 +117,8 @@ def __init__(
116117
self._custom_log_levels = None
117118
self._log_filepath = self._configure_logging(**log_config)
118119

120+
# clear notifier listeners from any previous simulation in this process
121+
notifier.clear_listeners()
119122

120123
# random number generator
121124
seed_from = "auto" if seed is None else "user"

0 commit comments

Comments
 (0)