baseclass: Avoid glib Source ID XX not found at app shutdown

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2024-03-03 11:54:11 -05:00
parent 6c9774267f
commit 75e4d1dd29

View File

@ -164,8 +164,20 @@ class vmmGObject(GObject.GObject):
GLib timeout_add wrapper to simplify callers, and track handles
for easy cleanup
"""
ret = GLib.timeout_add(timeout, func, *args)
id_list = []
def wrap_func(*wrapargs):
# When the our timeout_add callback returns False, remove
# the source ID from our cache, to avoid glib warnings like
# this at app shutdown:
# Warning: Source ID 60 was not found when attempting to remove it
func_ret = func(*wrapargs)
if not func_ret:
self.remove_gobject_timeout(id_list[0])
return func_ret
ret = GLib.timeout_add(timeout, wrap_func, *args)
self.add_gobject_timeout(ret)
id_list.append(ret)
return ret
def emit(self, signal_name, *args):