Some small bugs fixed
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user