summary refs log tree commit diff stats
path: root/plugins/python
diff options
context:
space:
mode:
authorCelelibi <celelibi@gmail.com>2023-04-03 05:25:47 +0200
committerPatrick <tingping@tingping.se>2023-04-24 17:10:41 -0500
commit5cbd2524dcedb995fc98403d1d73a3400e2cb935 (patch)
tree22a19b3d1ada2a360bf8ebfde1b4c37467d488c5 /plugins/python
parent847e5a14d6d7991682c3add853f7b3cc32f935df (diff)
python: fix for timers that unhook themselves
The python plugin use weak references for hooks, which might let a
necessary object disappear if the callback of a timer hook unhooks
itself.

Signed-off-by: Celelibi <celelibi@gmail.com>
Diffstat (limited to 'plugins/python')
-rw-r--r--plugins/python/python.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/plugins/python/python.py b/plugins/python/python.py
index 07900eb2..9eca7d6e 100644
--- a/plugins/python/python.py
+++ b/plugins/python/python.py
@@ -291,7 +291,15 @@ def _on_timer_hook(userdata):
     if hook.callback(hook.userdata) == True:
         return 1
 
-    hook.is_unload = True  # Don't unhook
+    try:
+        # Avoid calling hexchat_unhook twice if unnecessary
+        hook.is_unload = True
+    except ReferenceError:
+        # hook is a weak reference, it might have been destroyed by the callback
+        # in which case it has already been removed from hook.plugin.hooks and
+        # we wouldn't be able to test it with h == hook anyway.
+        return 0
+
     for h in hook.plugin.hooks:
         if h == hook:
             hook.plugin.hooks.remove(h)