-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if Task(Future) is canceled. #1377
Conversation
Signed-off-by: Tomoya Fujita <[email protected]>
Please backport this bugfix into humble/jazzy. |
Hey, def cancel(self):
if not self._done and iscoroutine(self._handle):
self._handle.close()
super().cancel() We can at least fix the bug at hand and concentrate on improving on the functionality after? |
@nadavelkabets @weber-niklas sorry guys for being late to get back to this, i will try to allocate some time for this in next week. |
I created PR #1392 to fix the unawaited coroutine issue based on my first suggestion. It's not yet complete since we need to figure out how to handle the CancelledException in a way that won't crash the executor. I believe we should first go with a solution that we can backport into jazzy. |
@nadavelkabets again thank you very much for helping this one moving forward 👍 i have already #1394 merged in this PR.
agree, this is also broken in jazzy and humble.
IMO, we can go with suggestion 2 (coroutine close, that is currently implemented in this PR) to avoid surprising the application with new exception generated by task cancel. that said it does not break the user space, user application can have the fix and also no user code change is required. And then probably we can move on to #1392 for rolling branch. i think having the capability for clean-up in the user callback makes sense for canceling tasks.
i will look into this for sure and leave some comments. |
* Add FutureState Signed-off-by: Nadav Elkabets <[email protected]> * Close canceled coroutine Signed-off-by: Nadav Elkabets <[email protected]> * Fixed behavior in test Signed-off-by: Nadav Elkabets <[email protected]> --------- Signed-off-by: Nadav Elkabets <[email protected]> Signed-off-by: Tomoya Fujita <[email protected]>
Signed-off-by: Tomoya Fujita <[email protected]>
c3107d6
to
59000b6
Compare
@fujitatomoya please review #1396, it includes some fixes I forgot to add in my last PR. |
@nadavelkabets thank for the PR against this one, can you also take a look at the unresolved comment here? that is directly related to #1396. |
I created a new PR #1397 that should close your comments @fujitatomoya. |
* Remove redundant coro.close Signed-off-by: nadav <[email protected]> * Only finished future is done Signed-off-by: nadav <[email protected]> * Add function _pending and fix checks Signed-off-by: = <[email protected]> * Replace check in done from pending to finished Signed-off-by: = <[email protected]> * Adapt test to new behavior Signed-off-by: = <[email protected]> * Add tests Signed-off-by: = <[email protected]> * Make changes within active task mutex Signed-off-by: = <[email protected]> --------- Signed-off-by: nadav <[email protected]> Signed-off-by: = <[email protected]>
…sts accordingly. Signed-off-by: Tomoya Fujita <[email protected]>
@nadavelkabets can you double-check 6cd294b just in case? that just removes some flake8 errors, and removed new exception that you introduced with previous commit. do you think this is okay? |
Looks good to me. |
Signed-off-by: Tomoya Fujita <[email protected]>
Pulls: #1377 |
@tfoote thanks for the review, i will address them. besides that, CI RHEL and Windows are not happy with |
Good catch. StrEnum was only added in python3.11. |
@nadavelkabets no that is fine, i can patch them today. |
Signed-off-by: Tomoya Fujita <[email protected]>
@tfoote @nadavelkabets addressed review comments, can you check fc3dd67? |
Pulls: #1377 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few suggestions to make sure we have better test coverage, but it looks good to me otherwise assuming CI passes.
Signed-off-by: Tomoya Fujita <[email protected]>
@nadavelkabets @weber-niklas @haudren-woven @tonygoldman just a quick heads up. thank you very much for being patient on this PR. this PR is almost ready to merge in rolling. once i confirm the all CI goes green, i will merge this to rolling branch 1st. since the original issue created on released distro (actually Foxy), and this is really nice to fix to downstream distros Jazzy and Humble, i will try to backport this after a couple of weeks soak time in rolling. and special thanks to @nadavelkabets for helping me to push forward this fix 👍 |
Awesome! It’s great news for any ‘async ros’ user! |
windows CI is green, merging. |
@Mergifyio backport humble jazzy |
✅ Backports have been created
|
* Check if Task(Future) is canceled. Signed-off-by: Tomoya Fujita <[email protected]> * Close cancelled coroutine (#1394) * Add FutureState Signed-off-by: Nadav Elkabets <[email protected]> * Close canceled coroutine Signed-off-by: Nadav Elkabets <[email protected]> * Fixed behavior in test Signed-off-by: Nadav Elkabets <[email protected]> --------- Signed-off-by: Nadav Elkabets <[email protected]> Signed-off-by: Tomoya Fujita <[email protected]> * address flake8 and pep257 failures. Signed-off-by: Tomoya Fujita <[email protected]> * Cancelled future is not done (#1397) * Remove redundant coro.close Signed-off-by: nadav <[email protected]> * Only finished future is done Signed-off-by: nadav <[email protected]> * Add function _pending and fix checks Signed-off-by: = <[email protected]> * Replace check in done from pending to finished Signed-off-by: = <[email protected]> * Adapt test to new behavior Signed-off-by: = <[email protected]> * Add tests Signed-off-by: = <[email protected]> * Make changes within active task mutex Signed-off-by: = <[email protected]> --------- Signed-off-by: nadav <[email protected]> Signed-off-by: = <[email protected]> * keep the consistent behavior to avoid exception, and adjusted some tests accordingly. Signed-off-by: Tomoya Fujita <[email protected]> * revert doc section to raise the exception. Signed-off-by: Tomoya Fujita <[email protected]> * remove StrEnum and put logical operator in the beginning of line. Signed-off-by: Tomoya Fujita <[email protected]> * add more test to check Task state. Signed-off-by: Tomoya Fujita <[email protected]> --------- Signed-off-by: Tomoya Fujita <[email protected]> Signed-off-by: Nadav Elkabets <[email protected]> Signed-off-by: nadav <[email protected]> Signed-off-by: = <[email protected]> Co-authored-by: Nadav Elkabets <[email protected]> Co-authored-by: Nadav Elkabets <[email protected]> (cherry picked from commit 9a144bf) # Conflicts: # rclpy/rclpy/executors.py # rclpy/rclpy/task.py # rclpy/test/test_executor.py
* Check if Task(Future) is canceled. Signed-off-by: Tomoya Fujita <[email protected]> * Close cancelled coroutine (#1394) * Add FutureState Signed-off-by: Nadav Elkabets <[email protected]> * Close canceled coroutine Signed-off-by: Nadav Elkabets <[email protected]> * Fixed behavior in test Signed-off-by: Nadav Elkabets <[email protected]> --------- Signed-off-by: Nadav Elkabets <[email protected]> Signed-off-by: Tomoya Fujita <[email protected]> * address flake8 and pep257 failures. Signed-off-by: Tomoya Fujita <[email protected]> * Cancelled future is not done (#1397) * Remove redundant coro.close Signed-off-by: nadav <[email protected]> * Only finished future is done Signed-off-by: nadav <[email protected]> * Add function _pending and fix checks Signed-off-by: = <[email protected]> * Replace check in done from pending to finished Signed-off-by: = <[email protected]> * Adapt test to new behavior Signed-off-by: = <[email protected]> * Add tests Signed-off-by: = <[email protected]> * Make changes within active task mutex Signed-off-by: = <[email protected]> --------- Signed-off-by: nadav <[email protected]> Signed-off-by: = <[email protected]> * keep the consistent behavior to avoid exception, and adjusted some tests accordingly. Signed-off-by: Tomoya Fujita <[email protected]> * revert doc section to raise the exception. Signed-off-by: Tomoya Fujita <[email protected]> * remove StrEnum and put logical operator in the beginning of line. Signed-off-by: Tomoya Fujita <[email protected]> * add more test to check Task state. Signed-off-by: Tomoya Fujita <[email protected]> --------- Signed-off-by: Tomoya Fujita <[email protected]> Signed-off-by: Nadav Elkabets <[email protected]> Signed-off-by: nadav <[email protected]> Signed-off-by: = <[email protected]> Co-authored-by: Nadav Elkabets <[email protected]> Co-authored-by: Nadav Elkabets <[email protected]> (cherry picked from commit 9a144bf) # Conflicts: # rclpy/rclpy/executors.py # rclpy/rclpy/task.py # rclpy/test/test_executor.py
closes #1099