Skip to content

Commit 5b971b0

Browse files
authored
Store references to streaming tasks (#615)
This makes sure they don't get garbage collected.
2 parents 953e320 + beb8db4 commit 5b971b0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,5 @@ This release replaces the `@actor` decorator with a new `Actor` class.
119119
- Fix `consumer_power` and `producer_power` similar to `pv_power`
120120

121121
- Zero value requests received by the `PowerDistributingActor` will now always be accepted, even when there are non-zero exclusion bounds.
122+
123+
- Hold on to a reference to all streaming tasks in the microgrid API client, so they don't get garbage collected.

src/frequenz/sdk/microgrid/client/_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def __init__(
216216
self.target = target
217217
self.api = MicrogridStub(grpc_channel)
218218
self._component_streams: Dict[int, Broadcast[Any]] = {}
219+
self._streaming_tasks: Dict[int, asyncio.Task[None]] = {}
219220
self._retry_spec = retry_spec
220221

221222
async def components(self) -> Iterable[Component]:
@@ -401,7 +402,7 @@ def _get_component_data_channel(
401402
chan = Broadcast[_GenericComponentData](task_name)
402403
self._component_streams[component_id] = chan
403404

404-
asyncio.create_task(
405+
self._streaming_tasks[component_id] = asyncio.create_task(
405406
self._component_data_task(
406407
component_id,
407408
transform,

0 commit comments

Comments
 (0)