Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/frequenz/sdk/_internal/_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import abc
import dataclasses
import logging
import traceback
import typing

from frequenz.channels import Broadcast, Receiver
Expand Down Expand Up @@ -140,13 +139,9 @@ def get_or_create(self, message_type: type[T], key: str) -> Broadcast[T]:
ValueError: If the channel exists and the message type does not match.
"""
if key not in self._channels:
if _logger.isEnabledFor(logging.DEBUG):
_logger.debug(
"Creating a new channel for key %r with type %s at:\n%s",
key,
message_type,
"".join(traceback.format_stack(limit=10)[:9]),
)
_logger.debug(
"Creating a new channel for key %r with type %s.", key, message_type
)
self._channels[key] = _Entry(
message_type, Broadcast(name=f"{self._name}-{key}")
)
Expand All @@ -158,14 +153,7 @@ def get_or_create(self, message_type: type[T], key: str) -> Broadcast[T]:
f"message type {message_type} is not the same as the existing "
f"message type {entry.message_type}."
)
if _logger.isEnabledFor(logging.DEBUG):
_logger.debug(
"%s at:\n%s",
error_message,
# We skip the last frame because it's this method, and limit the
# stack to 9 frames to avoid adding too much noise.
"".join(traceback.format_stack(limit=10)[:9]),
)
_logger.debug("%s", error_message)
raise ValueError(error_message)

return typing.cast(Broadcast[T], entry.channel)
Expand Down
Loading