Repository navigation
Tags
Tags
# Frequenz channels Release Notes ## Summary This release fixes timers ignoring the cancellation of a task waiting on them, which could make stopping a service hang for a whole timer interval. ## Bug Fixes - Cancelling a task that waits on a `MonotonicTimer`, directly or through `select()`, is no longer ignored when it arrives right after the timer was reset or ticked. Before, the task could keep waiting until the next tick, so stopping a service could hang for a whole timer interval.
# Frequenz channels Release Notes ## Summary This release fixes timers ignoring the cancellation of a task waiting on them, which could make stopping a service hang for a whole timer interval. ## Bug Fixes - Cancelling a task that waits on a `MonotonicTimer` (or the deprecated `Timer`), directly or through `select()`, is no longer ignored when it arrives right after the timer was reset or ticked. Before, the task could keep waiting until the next tick, so stopping a service could hang for a whole timer interval.
# Frequenz channels Release Notes
## Summary
This release removes what v1.13.0 deprecated, and it has breaking changes that v1.13.0 can't warn about, mostly in `BroadcastChannel`. Read the Upgrading section before upgrading. The main breaking changes are:
- A `BroadcastChannel` no longer closes when a message is sent while it has no receivers. `send()` raises the new `SenderHasNoReceiversError` instead, and the channel stays open, so code that relied on the channel closing has to catch the error.
- `BroadcastChannel()` takes `resend_latest` only by keyword, `BroadcastSender.subscribe()` uses the channel's `buffer_size` and `warn_on_overflow` as defaults, and `BroadcastSender.clone()` raises a `SenderClosedError` on a closed sender.
- `Receiver.close()` is abstract, so custom receivers have to implement it.
The new `frequenz.channels.Pipe` is a separate implementation that replaces `frequenz.channels.experimental.Pipe`, which is deprecated but still behaves as in v1. The new `Pipe` closes its sender, and by default its receiver too, in cases where the experimental one leaves them open, so check how your code shuts down before switching.
To upgrade, move to v1.13.0 first and fix all its deprecation warnings: every replacement already exists there, so a project can then require `frequenz-channels >= 1.13.0, < 3`. Then check the changes above, which can make the same code behave differently on v2. `Broadcast` still works, but stays deprecated.
## Upgrading
- `BroadcastChannel()` and `BroadcastSender.subscribe()` now take only the name by position. `resend_latest` (only in `BroadcastChannel()`), `buffer_size` and `warn_on_overflow` must be passed by keyword. A call that passes any of them by position fails with a `TypeError`. v1.13.0 already deprecates passing `warn_on_overflow` by position, but it doesn't warn about `resend_latest`, so look for calls like `BroadcastChannel("name", True)` and pass it by keyword.
- The deprecated `limit` argument of `BroadcastChannel()` and `BroadcastSender.subscribe()` is removed. Use `buffer_size` instead, which exists since v1.13.0, so you can migrate before upgrading. `Broadcast.new_receiver()` still takes `limit`.
- The deprecated `frequenz.channels.timer.Timer` is removed. Use `MonotonicTimer` instead, which exists since v1.13.0, so you can migrate before upgrading. The name `Timer` will be used for a wall clock timer in a later version.
- `Anycast` is removed. There is no replacement: copy its code into your project if you still need it.
- `frequenz.channels.experimental.GroupingLatestValueCache` is removed, together with its type variables `DefaultT`, `HashableT` and `ValueT_co`. Copy its code into your project if you still need it, or open an issue if you think it should stay in the library.
- `frequenz.channels.experimental.RelaySender` is removed. Copy its code into your project if you still need it, or open an issue if you think it should stay in the library.
- `frequenz.channels.experimental.OptionalReceiver` is removed. Use the receiver itself, or `frequenz.channels.NopReceiver` when there is none. `NopReceiver` exists since v1.13.0, so you can migrate before upgrading.
- `WithPrevious` and `NopReceiver` are no longer available from `frequenz.channels.experimental`. Import them from `frequenz.channels`, where they are available since v1.13.0, so you can migrate before upgrading.
- The deprecated `async close()` method of `Broadcast` is removed. Use `aclose()` instead, which exists since v1.8.0, so you can migrate before upgrading. It also works with `contextlib.aclosing()`.
- The `repr()` of a `BroadcastReceiver` shows its `buffer_size` instead of `limit`.
- A `BroadcastChannel`, or a `Broadcast` created with `auto_close=True`, no longer closes when a message is sent while it has no receivers. `send()` now drops the message and raises a `SenderHasNoReceiversError`, a `SenderError` without a cause. The channel stays open: `subscribe()` keeps working, and sending works again once a new receiver is attached.
- Code that waited for such a channel to close after a send without receivers, for example by checking for a `ChannelClosedError` cause or for `is_closed`, should catch `SenderHasNoReceiversError` instead. It can then stop sending, or close all of the channel's senders to close the channel.
- `frequenz.channels.experimental.Pipe` is deprecated and will be removed in v3.0.0. Use the new `frequenz.channels.Pipe` instead, but check how your code closes the sender and the receiver of the pipe first, as the two behave differently:
- When its receiver stops, the new `Pipe` closes its sender. The experimental one stops and leaves the sender open.
- When sending fails with a `SenderError` that isn't a `TransientSenderError`, the new `Pipe` logs the error and closes both its sender and its receiver by default. The experimental one lets the exception end its task and leaves both open.
- When sending fails with a `TransientSenderError`, like a `SenderHasNoReceiversError`, the new `Pipe` logs it, drops the message and keeps forwarding. The experimental one lets the exception end its task.
- With `close_pipe_on_send_error=False`, the new `Pipe` also drops the message that failed with any other `SenderError` and keeps forwarding the next ones. This doesn't bring back the behavior of the experimental one.
- `stop()` leaves both ends open in both.
- `BroadcastSender.clone()` now raises a `SenderClosedError` if the sender is closed, like `send()` and `subscribe()` do. Clone a sender before closing it, or catch `SenderClosedError`. A `Broadcast` can also be closed with `aclose()` while it still has open senders; after that, cloning any of them raises a `SenderError`.
- `BroadcastSender.subscribe()` now uses the `buffer_size` and `warn_on_overflow` values the `BroadcastChannel` was created with as defaults, instead of `50` and `True`. Pass `buffer_size=50, warn_on_overflow=True` to keep the old values.
- Call `BroadcastReceiver.close()` from the thread that runs the event loop of the channel's receivers. From another thread, tasks waiting on any receiver of the channel might not wake up. If asyncio debug mode is on and a task is waiting, `close()` also raises a `RuntimeError`, and the waiting tasks stay stuck. Use `loop.call_soon_threadsafe(receiver.close)` instead.
- `Receiver.close()` is now an abstract method, so a custom `Receiver` subclass that doesn't implement it can't be instantiated anymore. Before, calling it raised a `NotImplementedError`. All the receivers in this library implement it already. Add a `close()` method to your own receivers; the same implementation works on v1, so your code can support both major versions.
## New Features
- `TransientSenderError` is a new `SenderError` for errors after which the sender and its channel can still be used: only the message that failed wasn't sent. Catch it before `SenderError` to tell it apart from the errors that make a sender unusable.
- `SenderHasNoReceiversError` is a new `TransientSenderError`. An open sender of a `BroadcastChannel`, or of a `Broadcast` created with `auto_close=True`, raises it from `send()` while the channel is open but has no receivers. The message is dropped, but with `resend_latest=True`, new receivers still get it if it is the last message sent and it isn't `None`. The channel stays open, so sending works again once a receiver subscribes.
- `Pipe` is now available in `frequenz.channels`. It forwards all the messages from a receiver to a sender, like `frequenz.channels.experimental.Pipe`, but it also closes its ends: when its receiver stops it closes its sender, and when sending fails with a `SenderError` that isn't a `TransientSenderError` it closes its sender and its receiver, unless you pass `close_pipe_on_send_error=False`, in which case it drops the message and keeps going. When sending fails with a `TransientSenderError`, like a `SenderHasNoReceiversError`, it logs it, drops the message and keeps forwarding, whatever `close_pipe_on_send_error` says. See the `Pipe` documentation for what the pipe leaves open and who has to close it.
- `BroadcastSender.has_receivers` and `BroadcastReceiver.has_senders` tell whether the other side of a broadcast channel is still there, so producers can stop producing messages that nobody would receive. A sender that was garbage-collected without being closed still counts.
## Bug Fixes
- Closing a broadcast receiver now wakes up tasks waiting for messages on it, instead of leaving them blocked until the next message arrived or the channel was closed.
- Closing a broadcast receiver now drops the messages left in its buffer, so it is no longer reported as ready. So `select()` no longer reports it as stopped over and over, and no longer fails with a `SelectError` for a `filter()` on it.
- Sending to or closing a broadcast channel no longer raises `RuntimeError: Event loop is closed` when a receiver was left waiting on an event loop that has since been closed.
# Frequenz channels Release Notes ## Summary This will probably be the last minor release of v1. It deprecates everything that will be removed in v2.0.0. ## Upgrading - `frequenz-core >= 1.6.0, < 2` is now a runtime dependency. It provides the utilities this project uses to deprecate symbols following the Frequenz deprecations guide. - The minimum `typing-extensions` version is now 4.16.0. `frequenz-core` requires 4.13.0, and the new `buffer_size` argument needs the `sentinel` type added in 4.16.0. - `watchfiles` 1.2 and 1.3 are now allowed (`watchfiles >= 0.15.0, < 1.4.0`). - `frequenz.channels.Anycast`, deprecated since v1.12.0, will be removed in v2.0.0, with no replacement. Copy its code into your project if you need it. Its deprecation warning now says so. - `frequenz.channels.Broadcast`, deprecated since v1.12.0, now warns `frequenz.channels.Broadcast is deprecated. Use frequenz.channels.BroadcastChannel instead.`, instead of `Please use BroadcastChannel instead.`. - `Broadcast.close()` and `Anycast.close()`, deprecated since v1.8.0, will be removed in v2.0.0. Use `aclose()` instead. Their deprecation warnings now say so, and name the method and its class, as in `The method close() in frequenz.channels.Broadcast is deprecated and will be removed in v2.0.0. Use aclose() instead.` - `frequenz.channels.experimental.GroupingLatestValueCache`, with its type variables `DefaultT`, `HashableT` and `ValueT_co`, is deprecated and will be removed in v2.0.0, and so is `frequenz.channels.experimental.RelaySender`. There is no replacement in this library: copy their code into your project if you need them, or [open an issue](https://github.com/frequenz-floss/frequenz-channels-python/issues) if you think they should stay. - `frequenz.channels.experimental.NopReceiver` and `frequenz.channels.experimental.WithPrevious` are deprecated. Import them from `frequenz.channels` instead; they are the same objects, so only the import changes. The old names will be removed in v2.0.0, and their deprecation warnings say so. - `frequenz.channels.experimental.OptionalReceiver` will be removed in v2.0.0. Its deprecation warning now points at `frequenz.channels.NopReceiver`: use the receiver itself, or a `NopReceiver` when there is none. - `frequenz.channels.timer.Timer` was renamed to `MonotonicTimer`, to make clear it uses the event loop's monotonic clock and to free the name `Timer` for a wall clock timer in a later version. `Timer` still works as a deprecated alias and will be removed in v2.0.0, as its deprecation warning says. The change is mechanical: replace `Timer` with `MonotonicTimer` in imports and uses. - The `limit` argument of `BroadcastChannel()` and `BroadcastSender.subscribe()` is deprecated and will be removed in v2.0.0. Use the new `buffer_size` argument instead. It does the same, but its name says what is limited: the number of messages each receiver can hold. - `buffer_size` is keyword-only, and passing both `limit` and `buffer_size` raises a `TypeError`. - Passing `warn_on_overflow` by position is deprecated, since the `buffer_size` form only accepts it by keyword. - v2.0.0 will also make `resend_latest` keyword-only, so pass it by keyword now. - `Broadcast.new_receiver()` and `Anycast()` keep their `limit` argument. - v2.0.0 will make `Receiver.close()` abstract, so a custom receiver that doesn't implement it can't be instantiated anymore. Add a `close()` method to your own receivers now; the same code works on v1 and v2. ## New Features - `NopReceiver` and `WithPrevious` are now stable, and available from `frequenz.channels`. ## Bug Fixes - `BroadcastChannel()` no longer emits the deprecation warning of `Broadcast`, which it uses internally. You were getting a warning about a class you never used. - `OneshotReceiver.close()` no longer raises `NotImplementedError`. It now works like in the other receivers: a message sent before closing can still be received, and after that receiving raises `ReceiverStoppedError`. The sender can still send, but its message is discarded. - Creating a broadcast receiver with a `buffer_size` (or `limit`) of 0 now raises a `ValueError`, from `BroadcastChannel()` and `BroadcastSender.subscribe()`. Before, the first message sent to it raised an `IndexError`, after other receivers might have got the message already. - Docstrings now use absolute cross-references to public paths instead of relative ones. Relative cross-references are expanded from the module where an object is defined since mkdocstrings-python 2.0.9, which broke some links, and projects rendering docstrings inherited from this library needed `relative_crossrefs: true` for them to work at all. See [frequenz-repo-config-python#655](frequenz-floss/frequenz-repo-config-python#655) for details.
# Frequenz channels Release Notes ## Upgrading - The old `Broadcast` class is deprecated in favour of the new auto-closing `BroadcastChannel`. - The `Anycast` class is deprecated, because of the lack of use-cases and the maintenance cost. ## New Features - There's a new `BroadcastChannel`, which returns a broadcast sender and a broadcast receiver. The channel is auto-closing, meaning when all the senders or all the receivers are closed, the channel is closed.
# Frequenz channels Release Notes ## Upgrading - `LatestValueCache` now closes the receiver when it is stopped. - Fetching values from stopped `LatestValueCache` instances is now disallowed. ## New Features - There's a new `Oneshot` channel, which returns a sender and a receiver. A single message can be sent using the sender, after which it will be closed. And the receiver will close as soon as the message is received. - `Sender`s now have an `aclose`, which must be called, when they are no-longer needed.
# Frequenz channels Release Notes ## Summary This release introduces the experimental `GroupingLatestValueCache` and includes a couple of bug fixes. ## New Features - This release introduces the experimental `GroupingLatestValueCache`. It is similar to the `LatestValueCache`, but accepts an additional key-function as an argument, which takes each incoming message and returns a key for that message. The latest value received for each unique key gets cached and is available to look up on-demand through a `collections.abc.Mapping` interface. ## Bug Fixes - Any open calls to `NopReceiver.ready()` now return as soon as the receiver is closed. - The `__str__` representation of broadcast receivers now include the receiver's name.
# Frequenz channels Release Notes ## New Features - An experimental `NopReceiver` implementation has been added, which can be used as a place-holder receiver that never receives a message. - The experimental `OptionalReceiver` has been deprecated. It will be removed with the next major release. It can be replaced with a `NopReceiver` as follows: ```python opt_recv: Receiver[T] | None recv: Receiver[T] = NopReceiver[T]() if opt_recv is None else opt_recv ```
# Frequenz channels Release Notes ## Summary This release focuses on improving `async` patterns and flexibility in the channel's library. ## 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 - Add a new `OptionalReceiver` class that wraps an optional underlying receiver, allowing for indefinite waiting when no receiver is set. - Improve documentation of the `frequenz.channels.experimental.Pipe`
# Frequenz channels Release Notes ## New Features - An optional `tick_at_start` parameter has been added to `Timer`. When `True`, the timer will trigger immediately after starting, and then wait for the interval before triggering again. ## Bug Fixes - Fix unterminated code block in a documentation example for `WithPrevious`.
PreviousNext