Skip to content

Commit a1bfc11

Browse files
committed
Fix: Make streams local, not global
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 0056292 commit a1bfc11

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Bug Fixes
44

5-
* Fix missing dependency in last release
5+
* Fix missing dependency in last release.
66
* The `FakeClient.set_dispatches()` method now correctly updates `FakeService._last_id` which is used to generate unique dispatch IDs.
7+
* Fix that streams were globally shared between all clients.
78

src/frequenz/client/dispatch/_client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@
5555
class Client(BaseApiClient[dispatch_pb2_grpc.MicrogridDispatchServiceStub]):
5656
"""Dispatch API client."""
5757

58-
streams: dict[
59-
int, GrpcStreamBroadcaster[StreamMicrogridDispatchesResponse, DispatchEvent]
60-
] = {}
61-
"""A dictionary of streamers, keyed by microgrid_id."""
62-
6358
def __init__(
6459
self,
6560
*,
@@ -91,6 +86,10 @@ def __init__(
9186
),
9287
)
9388
self._metadata = (("key", key),)
89+
self._streams: dict[
90+
int, GrpcStreamBroadcaster[StreamMicrogridDispatchesResponse, DispatchEvent]
91+
] = {}
92+
"""A dictionary of streamers, keyed by microgrid_id."""
9493

9594
@property
9695
def stub(self) -> dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub:
@@ -225,11 +224,11 @@ def _get_stream(
225224
self, microgrid_id: int
226225
) -> GrpcStreamBroadcaster[StreamMicrogridDispatchesResponse, DispatchEvent]:
227226
"""Get an instance to the streaming helper."""
228-
broadcaster = self.streams.get(microgrid_id)
227+
broadcaster = self._streams.get(microgrid_id)
229228
# pylint: disable=protected-access
230229
if broadcaster is not None and broadcaster._channel.is_closed:
231230
# pylint: enable=protected-access
232-
del self.streams[microgrid_id]
231+
del self._streams[microgrid_id]
233232
broadcaster = None
234233
if broadcaster is None:
235234
request = StreamMicrogridDispatchesRequest(microgrid_id=microgrid_id)
@@ -244,7 +243,7 @@ def _get_stream(
244243
transform=DispatchEvent.from_protobuf,
245244
retry_strategy=LinearBackoff(interval=1, limit=0),
246245
)
247-
self.streams[microgrid_id] = broadcaster
246+
self._streams[microgrid_id] = broadcaster
248247

249248
return broadcaster
250249

0 commit comments

Comments
 (0)