@@ -84,7 +84,7 @@ def __init__(self, name: str, resend_latest: bool = False) -> None:
8484 get the latest value as soon as they are created, without having
8585 to wait for the next message on the channel to arrive.
8686 """
87- self .name : str = name
87+ self ._name : str = name
8888 """The name of the broadcast channel.
8989
9090 Only used for debugging purposes.
@@ -93,13 +93,13 @@ def __init__(self, name: str, resend_latest: bool = False) -> None:
9393 self ._resend_latest = resend_latest
9494 """Whether to resend the latest value to new receivers."""
9595
96- self .recv_cv : Condition = Condition ()
96+ self ._recv_cv : Condition = Condition ()
9797 """The condition to wait for data in the channel's buffer."""
9898
99- self .receivers : dict [UUID , weakref .ReferenceType [Receiver [T ]]] = {}
99+ self ._receivers : dict [UUID , weakref .ReferenceType [Receiver [T ]]] = {}
100100 """The receivers attached to the channel, indexed by their UUID."""
101101
102- self .closed : bool = False
102+ self ._closed : bool = False
103103 """Whether the channel is closed."""
104104
105105 self ._latest : T | None = None
@@ -117,9 +117,9 @@ async def close(self) -> None:
117117 immediately.
118118 """
119119 self ._latest = None
120- self .closed = True
121- async with self .recv_cv :
122- self .recv_cv .notify_all ()
120+ self ._closed = True
121+ async with self ._recv_cv :
122+ self ._recv_cv .notify_all ()
123123
124124 def new_sender (self ) -> Sender [T ]:
125125 """Create a new broadcast sender.
@@ -147,7 +147,7 @@ def new_receiver(self, name: str | None = None, maxsize: int = 50) -> Receiver[T
147147 if name is None :
148148 name = str (uuid )
149149 recv : Receiver [T ] = Receiver (uuid , name , maxsize , self )
150- self .receivers [uuid ] = weakref .ref (recv )
150+ self ._receivers [uuid ] = weakref .ref (recv )
151151 if self ._resend_latest and self ._latest is not None :
152152 recv .enqueue (self ._latest )
153153 return recv
@@ -193,23 +193,24 @@ async def send(self, msg: T) -> None:
193193 A [ChannelClosedError][frequenz.channels.ChannelClosedError] is
194194 set as the cause.
195195 """
196- if self ._chan .closed :
196+ # pylint: disable=protected-access
197+ if self ._chan ._closed :
197198 raise SenderError ("The channel was closed" , self ) from ChannelClosedError (
198199 self ._chan
199200 )
200- # pylint: disable=protected-access
201201 self ._chan ._latest = msg
202202 stale_refs = []
203- for name , recv_ref in self ._chan .receivers .items ():
203+ for name , recv_ref in self ._chan ._receivers .items ():
204204 recv = recv_ref ()
205205 if recv is None :
206206 stale_refs .append (name )
207207 continue
208208 recv .enqueue (msg )
209209 for name in stale_refs :
210- del self ._chan .receivers [name ]
211- async with self ._chan .recv_cv :
212- self ._chan .recv_cv .notify_all ()
210+ del self ._chan ._receivers [name ]
211+ async with self ._chan ._recv_cv :
212+ self ._chan ._recv_cv .notify_all ()
213+ # pylint: enable=protected-access
213214
214215
215216class Receiver (BaseReceiver [T ]):
@@ -271,7 +272,7 @@ def enqueue(self, msg: T) -> None:
271272 self ._q .popleft ()
272273 logger .warning (
273274 "Broadcast receiver [%s:%s] is full. Oldest message was dropped." ,
274- self ._chan .name ,
275+ self ._chan ._name , # pylint: disable=protected-access
275276 self ._name ,
276277 )
277278 self ._q .append (msg )
@@ -307,18 +308,22 @@ async def ready(self) -> bool:
307308 #
308309 # The condition also makes sure that if there are already messages ready to be
309310 # consumed, then we return immediately.
311+ # pylint: disable=protected-access
310312 while len (self ._q ) == 0 :
311- if self ._chan .closed :
313+ if self ._chan ._closed :
312314 return False
313- async with self ._chan .recv_cv :
314- await self ._chan .recv_cv .wait ()
315+ async with self ._chan ._recv_cv :
316+ await self ._chan ._recv_cv .wait ()
315317 return True
318+ # pylint: enable=protected-access
316319
317320 def _deactivate (self ) -> None :
318321 """Set the receiver as inactive and remove it from the channel."""
319322 self ._active = False
320- if self ._uuid in self ._chan .receivers :
321- del self ._chan .receivers [self ._uuid ]
323+ # pylint: disable=protected-access
324+ if self ._uuid in self ._chan ._receivers :
325+ del self ._chan ._receivers [self ._uuid ]
326+ # pylint: enable=protected-access
322327
323328 def consume (self ) -> T :
324329 """Return the latest value once `ready` is complete.
@@ -337,7 +342,7 @@ def consume(self) -> T:
337342 self ,
338343 )
339344
340- if not self ._q and self ._chan .closed :
345+ if not self ._q and self ._chan ._closed : # pylint: disable=protected-access
341346 raise ReceiverStoppedError (self ) from ChannelClosedError (self ._chan )
342347
343348 assert self ._q , "`consume()` must be preceded by a call to `ready()`"
0 commit comments