Keep Track of Active Notifiers. Make Notifier usable as ContextManager. by zariiii9003 · Pull Request #1890 · hardbyte/python-can
@zariiii9003 can we make this NotifierRegistry a little more "public"?
For example we could have a Notifier factory (for a given Bus instance give me the existing Notifier or create a new one), etc.
This would make things a bit more complicated.
- We could add a
__new__method to the Notifier where we check if a Notifier already exists and return that. But the Notifier can be instantiated with a list of BusABC objects, these might be already assigned to multiple other notifiers. And the listeners could be different in the existing instance, too. This might get difficult to handle, it's easier to just always raise an error in that case. - The user should not directly call the register and unregister methods, so i'd rather keep the registry itself private.
However, a Notifier.find(bus) -> Notifier classmethod or something like that would be easy to add.
What kind of solution did you have in mind?