Clean up the async start_task#178
Merged
Merged
Conversation
Contributor
Author
|
Also errors from closing the ssh connection are being caught. This should hopefully fix #177 |
Unfortunately the python3.5 version of `Task` doesn't have a means to determine if a task has finished vs done. Instead the internal `_state` method needs to be checked. To increase the maintainability, the method for doing this has been extracted into `finished`. This will make it easier to update in the future if need be
Previously all tasks running in the event loop would be cancelled. However this makes the callback behaviour unpredictable as the main Future was also being cancelled. The main Future (aka `start_tasks`) still gets cancelled. This stops `add_tasks` from running. However the `await_finished` will continue running. This ensures the other Futures finish correctly The `CancelledError` catch has been moved to where the error is being generated
Closing the ssh connection prematurely can lead to some ssh errors. In an attempt to catch these, all errors from the close method are being caught. Also the redundant catch of `CancelledError` has been removed
d5c75d3 to
8741ede
Compare
DavidMarchant
approved these changes
Nov 19, 2018
Contributor
DavidMarchant
left a comment
There was a problem hiding this comment.
This is all a little black magic-y but looks good to me!
Closed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Based on #176
This PR cleans up the
start_taskasync method. Most of the changes are code readability changes and do not affect functionality.There has been a change in the control logic concerning interrupt. Previously all the futures where being cancelled. This is fine for the
JobTasks as this triggers them to shutdown as expected. However it also cancels the main future which is runningstart_tasks. This will kill the event loop prematurely and makes the callback behaviour of the other futures difficult to predict.Instead the
start_taskswill catch theCancelledErrorand still shutdown as per normal. This prevents additional futures from starting BUT allows currently running (/recently cancelled) futures to shutdown gracefully.