From 9511ac7d20b4fdd471039d7756a912f319111c8a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Jul 2022 10:04:56 +0200 Subject: [PATCH] examples: fix tracking destruction in destroy_nmc() While iterating the context (once), multiple sources can be dispatched. So if we get a timeout and shortly after the weak-ref callback, then we still need to honor the weak-ref. In particular, because weak_ref.unref() is not safe to do after the object was already destroyed. So we need to be correct about tracking destruction. --- examples/python/gi/gmaincontext.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/python/gi/gmaincontext.py b/examples/python/gi/gmaincontext.py index b7ebf78e6d..90a9fa2542 100755 --- a/examples/python/gi/gmaincontext.py +++ b/examples/python/gi/gmaincontext.py @@ -375,9 +375,9 @@ def destroy_nmc(nmc_holder): finished = [] def _weak_ref_cb(): - if not finished: - log(f"[destroy_nmc]: context busy watcher is gone") - finished.append(True) + log(f"[destroy_nmc]: context busy watcher is gone") + finished.clear() + finished.append(True) # We take a weak ref on the context-busy-watcher object and give up # our reference on nmc. This must be the last reference, which initiates