Some small bugs fixed

This commit is contained in:
2025-08-01 21:24:54 +02:00
parent 8b4105a261
commit 5b31da96d4
9 changed files with 66 additions and 17 deletions

View File

@ -1,6 +1,8 @@
import threading
import queue
import logging
import inspect
import types
class EventBus:
@ -42,3 +44,20 @@ class EventBus:
callback(data)
except queue.Empty:
break
def unsubscribe_instance(self, instance):
"""
Remove every subscriber callback that is a bound method
on the given `instance`, across all event types.
"""
for event_type, subs in list(self.subscribers.items()):
new_subs = []
for callback, main_thread in subs:
# if it's a bound method to our instance, skip it
if inspect.ismethod(callback) and callback.__self__ is instance:
continue
new_subs.append((callback, main_thread))
if len(new_subs) != len(subs):
self.subscribers[event_type] = new_subs
print(self.subscribers)