Debounce calls to Plex server#33560
Merged
balloob merged 5 commits intohome-assistant:devfrom Apr 4, 2020
Merged
Conversation
balloob
reviewed
Apr 3, 2020
balloob
reviewed
Apr 3, 2020
balloob
approved these changes
Apr 4, 2020
This was referenced Apr 4, 2020
balloob
pushed a commit
that referenced
this pull request
Apr 5, 2020
* Debounce calls to Plex server * Simplify debounce by recommendation * Update tests to handle debounce * Test debouncer, fix & optimize tests * Use property instead
balloob
reviewed
Apr 6, 2020
| if unsub: | ||
| _LOGGER.debug("Throttling update of %s", self.friendly_name) | ||
| unsub() # pylint: disable=not-callable | ||
| unsub = async_call_later( |
Member
There was a problem hiding this comment.
This is calling an async method from a sync context.
balloob
reviewed
Apr 6, 2020
| nonlocal unsub | ||
| if unsub: | ||
| _LOGGER.debug("Throttling update of %s", self.friendly_name) | ||
| unsub() # pylint: disable=not-callable |
Member
There was a problem hiding this comment.
unsub functions should only be called from the same context as in which they are set. So if created with async_call_later, need to be called from inside the event loop.
Also, because this is running in a thread, you cannot guarantee that nothing else touches it. You should instead run this all inside the event loop.
Member
There was a problem hiding this comment.
It's better to turn this the wrapper function into an async function.
Contributor
Author
There was a problem hiding this comment.
Really sorry about that, hopefully fixed in #33730.
20 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
Updates for Plex
media_playerandsensorentities are triggered whenever a callback is received on a websocket listener. Sometimes these can come in rapid succession and it appears they can cause race conditions where objects are updated while they're being used. It's important to throttle the updates but also not "lose" the last request to update as updates can arrive very infrequently.A different approach to #33534 which I believe is addressing a symptom instead of the root cause.
Type of change
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: