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.
This commit is contained in:
Thomas Haller 2022-07-13 10:04:56 +02:00
parent 4655b7c308
commit 9511ac7d20
No known key found for this signature in database
GPG Key ID: 29C2366E4DFC5728

View File

@ -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