Labels
part:codeAffects the code in generalpart:docsAffects the documentationpriority:highAddress this as soon as possiblescope:breaking-changeBreaking change, users will need to update their codetype:enhancementNew feature or enhancement visitble to users
Milestone
Description
What's needed?
We need to make it more intuitive for users to be able to add cleanup logic to sub-classes. Right now users need to override __aexit__ which has more complexity than disconnect() (extra arguments), which users usually don't need to care about.
Proposed solution
- Move cleanup logic from
__aexit__()todisconnect()and calldisconnect()from__aexit__(like we callconnect()in__aenter__). - Document how users should add cleanup code overriding
disconnect()(probably add an example with stopping broadcasters, being that one very common use case).
Use cases
- Stopping and cleaning up broadcasters.
Additional context
The current BaseApiClient implementation calls __aexit__() from disconnect(). I found two public downstream overrides that rely on that call to clean up streams:
frequenz-client-microgrid-python:MicrogridApiClient.__aexit__()stops and clears its broadcasters before callingsuper().__aexit__().frequenz-client-dispatch-python: PR #356, Stop running streams on disconnect, introducesDispatchApiClient.__aexit__()to stop and clear its stream broadcasters. The PR is open, so the override is not on the default branch yet.
I didn't find any disconnect() overrides in the public client implementations I checked. When these clients adopt v0.12.0, they'll need to move the cleanup into disconnect() so it still runs on both explicit disconnect and async with exit.
Metadata
Metadata
Assignees
Labels
part:codeAffects the code in generalpart:docsAffects the documentationpriority:highAddress this as soon as possiblescope:breaking-changeBreaking change, users will need to update their codetype:enhancementNew feature or enhancement visitble to users
Type
Fields
Priority
High
Effort
Low
Activity