You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The minimum Python supported version was bumped to 3.11 and the Select class replaced by the new select() function.
Upgrading
The minimum supported Python version was bumped to 3.11, downstream projects will need to upgrade too to use this version.
The Select class was replaced by a new select() function, with the following improvements:
Type-safe: proper type hinting by using the new helper type guard selected_from().
Fixes potential starvation issues.
Simplifies the interface by providing values one-by-one.
Guarantees there are no dangling tasks left behind when used as an async context manager.
This new function is an async iterator, and makes sure no dangling tasks are left behind after a select loop is done.
Example:
timer1=Timer.periodic(datetime.timedelta(seconds=1))
timer2=Timer.timeout(datetime.timedelta(seconds=0.5))
asyncforselectedinselect(timer1, timer2):
ifselected_from(selected, timer1):
# Beware: `selected.value` might raise an exception, you can always# check for exceptions with `selected.exception` first or use# a try-except block. You can also quickly check if the receiver was# stopped and let any other unexpected exceptions bubble up.ifselected.was_stopped():
print("timer1 was stopped")
continueprint(f"timer1: now={datetime.datetime.now()} drift={selected.value}")
timer2.stop()
elifselected_from(selected, timer2):
# Explicitly handling of exceptionsmatchselected.exception:
caseReceiverStoppedError():
print("timer2 was stopped")
caseException() asexception:
print(f"timer2: exception={exception}")
caseNone:
# All good, no exception, we can use `selected.value` safelyprint(
f"timer2: now={datetime.datetime.now()} "f"drift={selected.value}"
)
case _ asunhanded:
assert_never(unhanded)
else:
# This is not necessary, as select() will check for exhaustiveness, but# it is good practice to have it in case you forgot to handle a new# receiver added to `select()` at a later point in time.assertFalse
New Features
A new select() function was added, please look at the Upgrading section for details.
A new Event utility receiver was added.
This receiver can be made ready manually. It is mainly useful for testing but can also become handy in scenarios where a simple, on-off signal needs to be sent to a select loop for example.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Frequenz Channels Release Notes
Summary
The minimum Python supported version was bumped to 3.11 and the
Selectclass replaced by the newselect()function.Upgrading
The minimum supported Python version was bumped to 3.11, downstream projects will need to upgrade too to use this version.
The
Selectclass was replaced by a newselect()function, with the following improvements:selected_from().This new function is an async iterator, and makes sure no dangling tasks are left behind after a select loop is done.
Example:
New Features
A new
select()function was added, please look at the Upgrading section for details.A new
Eventutility receiver was added.This receiver can be made ready manually. It is mainly useful for testing but can also become handy in scenarios where a simple, on-off signal needs to be sent to a select loop for example.
Example:
The
Timerclass now has more descriptive__str__and__repr__methods.What's Changed
Selectwithselect(), a type-safe async iterator by @leandro-lucarella-frequenz in ReplaceSelectwithselect(), a type-safe async iterator #114New Contributors
Full Changelog: v0.15.1...v0.16.0
This discussion was created from the release v0.16.0.
Beta Was this translation helpful? Give feedback.
All reactions