Keep Track of Active Notifiers. Make Notifier usable as ContextManager. - #1890
Conversation
@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. |
zariiii9003
commented
Nov 6, 2024
This would make things a bit more complicated.
However, a What kind of solution did you have in mind? |
bessman
commented
Nov 7, 2024
This would be great! If I understand correctly, without such a classmethod this PR in its current state does not solve the example I put forth in #1888 (comment). A |
e06fc55 to
e35610aCompareUh oh!
There was an error while loading. Please reload this page.
| :param bus: A :ref:`bus` or a list of buses to listen to. | ||
| :param bus: | ||
| A :ref:`bus` or a list of buses to listen to. |
There was a problem hiding this comment.
| A :ref:`bus`oralistofbusestolistento. | |
| A :ref:`bus`oralistofbusestoconsumemessagesfrom. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| self._readers: List[Union[int, threading.Thread]] = [] | ||
| buses = self.bus if isinstance(self.bus, list) else [self.bus] | ||
| for each_bus in buses: | ||
| self._bus_list = self.bus if isinstance(self.bus, list) else [self.bus] |
There was a problem hiding this comment.
self._bus_list won't be correct after a user adds an additional Bus via add_bus, instead prefer to create an empty bus list here in the initializer, but add them inside the add_bus method.
There was a problem hiding this comment.
Good catch. The same was true for self.bus, i changed that to a property.
f9095a0 to
1708ddaCompare
Notifier.stop(). Adapt examples to usewith can.Notifier(...)