From e488a79096fb362aff358ca4d150f88f51c6e7d3 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Wed, 26 Feb 2025 18:03:42 +0000
Subject: [PATCH] TEST: Test Notifier handling GC'd callback functions

---
 fsl/tests/test_notifier.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/fsl/tests/test_notifier.py b/fsl/tests/test_notifier.py
index c85df509f..d3ead8c66 100644
--- a/fsl/tests/test_notifier.py
+++ b/fsl/tests/test_notifier.py
@@ -204,3 +204,31 @@ def test_skip():
     t.notify(topic='topic')
     assert default_called[0] == 14
     assert topic_called[  0] == 6
+
+
+# Make sure there is no error
+# if a callback function is GC'd
+# fsl/fslpy!470
+def test_gc():
+
+    class Thing(notifier.Notifier):
+        pass
+
+    t = Thing()
+
+    called = []
+
+    def callback(thing, topic, value):
+        called.append((thing, topic, value))
+
+    t.register('callback', callback)
+
+    t.notify()
+    assert called == [(t, None, None)]
+
+    called[:] = []
+    callback  = None
+    del callback
+
+    t.notify()
+    assert called == []
-- 
GitLab