backends/scanner: add handle_early_stop hooks #1146
Draft
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.
This is inspired by #1140 (comment). Quite a long time ago, I noticed that we weren't really handling scanner stop events when a scanner stops before we actually request it to. (This is somewhat similar to how we have a disconnect event for devices except in that case, the callback is called even if we requested the disconnect or not.) There haven't been any reported problems due to not having such a feature until now, so it has never been addressed until now.
So far, this PR just implements the platform-specific parts to call a common scanner backend method when an unrequested scanner stop event occurs. The idea is to use this as part of the context manager so that it will cancel the task if an early stop happens.
We probably also need some sort of API for anyone using
start
andstop
without a context manager (although maybe we don't want to support this and require a context manager if you want the callback to do something?).Code hasn't been tested yet on any platform, so expect bugs.
cc: @bojanpotocnik