Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
## Upgrading

- Some minimal dependencies have been bumped, so you might need to adjust your dependencies accordingly.
- `Broadcast` and `Anycast` channels method `close()` was renamed to `aclose()` to follow Python's convention. With this change now channels can be used with the [`aclosing()`](https://docs.python.org/3/library/contextlib.html#contextlib.aclosing) context manager for example.

The name `close()` is still available for backwards compatibility, but it will be removed in the next major release, so it is recommended to switch to `aclose()`.

## New Features

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmark_anycast.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def update_tracker_on_receive(chan: Receiver[int]) -> None:

await asyncio.gather(*senders)
for bcast in channels:
await bcast.close()
await bcast.aclose()
await receivers_runs
return recv_trackers[0]

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmark_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def update_tracker_on_receive(chan: Receiver[int]) -> None:

await asyncio.gather(*senders)
for bcast in channels:
await bcast.close()
await bcast.aclose()
await receivers_runs
recv_tracker = sum(recv_trackers)
assert recv_tracker == num_messages * num_channels * num_receivers
Expand Down
11 changes: 8 additions & 3 deletions src/frequenz/channels/_anycast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from collections import deque
from typing import Generic, TypeVar

from typing_extensions import override
from typing_extensions import deprecated, override

from ._exceptions import ChannelClosedError
from ._generic import ChannelMessageT
Expand Down Expand Up @@ -78,7 +78,7 @@ class Anycast(Generic[ChannelMessageT]):
respectively.

When the channel is not needed anymore, it should be closed with the
[`close()`][frequenz.channels.Anycast.close] method. This will prevent further
[`aclose()`][frequenz.channels.Anycast.aclose] method. This will prevent further
attempts to [`send()`][frequenz.channels.Sender.send] data. Receivers will still be
able to drain the pending messages on the channel, but after that, subsequent
[`receive()`][frequenz.channels.Receiver.receive] calls will raise a
Expand Down Expand Up @@ -266,7 +266,7 @@ def limit(self) -> int:
assert maxlen is not None
return maxlen

async def close(self) -> None:
async def aclose(self) -> None:
"""Close the channel.

Any further attempts to [send()][frequenz.channels.Sender.send] data
Expand All @@ -283,6 +283,11 @@ async def close(self) -> None:
async with self._recv_cv:
self._recv_cv.notify_all()

@deprecated("The close() method is deprecated, use aclose() instead")
async def close(self) -> None: # noqa: D402
"""Close the channel, deprecated alias for `aclose()`.""" # noqa: D402
return await self.aclose()

def new_sender(self) -> Sender[ChannelMessageT]:
"""Return a new sender attached to this channel."""
return _Sender(self)
Expand Down
11 changes: 8 additions & 3 deletions src/frequenz/channels/_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections import deque
from typing import Generic, TypeVar

from typing_extensions import override
from typing_extensions import deprecated, override

from ._exceptions import ChannelClosedError
from ._generic import ChannelMessageT
Expand Down Expand Up @@ -65,7 +65,7 @@ class Broadcast(Generic[ChannelMessageT]):
respectively.

When a channel is not needed anymore, it should be closed with
[`close()`][frequenz.channels.Broadcast.close]. This will prevent further
[`aclose()`][frequenz.channels.Broadcast.aclose]. This will prevent further
attempts to [`send()`][frequenz.channels.Sender.send] data, and will allow
receivers to drain the pending items on their queues, but after that,
subsequent [receive()][frequenz.channels.Receiver.receive] calls will
Expand Down Expand Up @@ -248,7 +248,7 @@ def is_closed(self) -> bool:
"""
return self._closed

async def close(self) -> None:
async def aclose(self) -> None:
"""Close this channel.

Any further attempts to [send()][frequenz.channels.Sender.send] data
Expand All @@ -264,6 +264,11 @@ async def close(self) -> None:
async with self._recv_cv:
self._recv_cv.notify_all()

@deprecated("The close() method is deprecated, use aclose() instead")
async def close(self) -> None: # noqa: D402
"""Close the channel, deprecated alias for `aclose()`.""" # noqa: D402
return await self.aclose()

def new_sender(self) -> Sender[ChannelMessageT]:
"""Return a new sender attached to this channel."""
return _Sender(self)
Expand Down