Skip to content
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

Make context.on_shutdown allow free functions as shutdown callbacks #859

Merged
merged 1 commit into from
Dec 10, 2021

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Dec 9, 2021

Split from #858

WeakMethod throws an exception if the callable is not a bound method, which prevented using free functions as a shutdown callback. This allows free functions by storing them with weakref.ref.

Example exception before this PR

9: >           raise TypeError("argument should be a bound method, not {}"
9:                             .format(type(meth))) from None
9: E           TypeError: argument should be a bound method, not <class 'function'>

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
@sloretz sloretz self-assigned this Dec 9, 2021
Copy link

@j-rivero j-rivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great.

@sloretz
Copy link
Contributor Author

sloretz commented Dec 9, 2021

CI (build: --packages-above-and-dependencies rclpy test: --packages-above rclpy)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@sloretz sloretz merged commit b0e1266 into master Dec 10, 2021
@delete-merged-branch delete-merged-branch bot deleted the on_shutdown_with_free_function branch December 10, 2021 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants