Skip to content

Conversation

@nadavelkabets
Copy link
Contributor

Part of #1399.

  • Expose set_on_new_message_callback and clear_on_new_message_callback for subscription.
  • Expose set_on_new_request_callback and clear_on_new_request_callback for service.
  • Expose set_on_new_response_callback and clear_on_new_response_callback for client.
  • Expose set_on_reset_callback and clear_on_reset_callback for timer.

Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
@nadavelkabets nadavelkabets force-pushed the feature/on-new-message-callback branch from d4de3d0 to 8094f15 Compare August 30, 2025 19:52
Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
@nadavelkabets
Copy link
Contributor Author

nadavelkabets commented Aug 30, 2025

@sloretz @fujitatomoya @mjcarroll @wjwwood @ahcorde
The PR is complete with unit tests.
The python callback provided by the user is wrapped by pybind and gets executed in the rcl event trampoline.
Any exception raised in the python callback might result in a core dump since the event trampoline executes in a pure c environment.
To prevent core dumps, I wrapped user callbacks in the asyncio executor with an exception handler that logs exceptions.
I'm not sure if that's a big issue as this code is not exposed to the end user and should only be accessed by an executor implementation.
What do you think?

Signed-off-by: Nadav Elkabets <[email protected]>
@nadavelkabets
Copy link
Contributor Author

nadavelkabets commented Sep 6, 2025

@mjcarroll @wjwwood @skyegalaxy
Following our discussion in the meeting group, I added exception handling in the rcl trampoline that prints any exception and exits to avoid propagation into c code.

@nadavelkabets
Copy link
Contributor Author

@fujitatomoya do you have the time to take a look at this PR?

@skyegalaxy
Copy link
Member

looking at the PR just from a C++ and python perspective, everything looks alright to me. I'll defer to others with more rclpy experience as I've mostly spent time on the rclcpp side. I appreciate that the code will now bubble up the exceptions and exit instead of silently failing!

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

lgtm too, with a small non-blocking suggestion

Co-authored-by: William Woodall <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
@nadavelkabets
Copy link
Contributor Author

Would be great to run CI on this PR.
Is anybody available?

@fujitatomoya
Copy link
Collaborator

Pulls: #1496
Gist: https://gist.githubusercontent.com/fujitatomoya/7983ca49fce3c3d9e3fd1bc3da1b814f/raw/323fcc8714382080808b8734f120667ba00b692e/ros2.repos
BUILD args: --packages-above-and-dependencies rclpy
TEST args: --packages-above rclpy
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16942

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

@wjwwood thanks for reviewing this 🚀

@nadavelkabets CI is just started.

@nadavelkabets nadavelkabets force-pushed the feature/on-new-message-callback branch from 0fea2c1 to 095f3d0 Compare September 13, 2025 19:39
Signed-off-by: Nadav Elkabets <[email protected]>
@nadavelkabets nadavelkabets force-pushed the feature/on-new-message-callback branch from 095f3d0 to e2452bb Compare September 13, 2025 19:42
@nadavelkabets
Copy link
Contributor Author

@fujitatomoya I made the following fixes:
diff link: e2452bb

  • Add docstring in .pyi
  • Call std::terminate instead of std::exit upon unhandled exception
  • Improve the exception string when throwing RCLError
  • clear any existing callback when destroying an entity

Could you please run CI again?

@fujitatomoya
Copy link
Collaborator

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

@nadavelkabets all gree, i will go ahead to merge this. thank you very much for your contribution.

@fujitatomoya fujitatomoya merged commit c834c24 into ros2:rolling Sep 15, 2025
3 checks passed
@nadavelkabets
Copy link
Contributor Author

@fujitatomoya Could we backport this as well?

@fujitatomoya
Copy link
Collaborator

@Mergifyio backport kilted jazzy

@mergify
Copy link
Contributor

mergify bot commented Sep 17, 2025

backport kilted jazzy

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 17, 2025
…t and timer (#1496)

* Added set_on_new_response_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added set_on_new_request_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added set_on_new_message_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added set_on_reset_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added type hints to pyi

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for subscription

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for timer

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for client

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for service

Signed-off-by: Nadav Elkabets <[email protected]>

* Fixed lint

Signed-off-by: Nadav Elkabets <[email protected]>

* Avoid throwing into c code

Signed-off-by: Nadav Elkabets <[email protected]>

* Print newline after logging exception

Co-authored-by: William Woodall <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>

* Improve logging and cleanup

Signed-off-by: Nadav Elkabets <[email protected]>

---------

Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
Co-authored-by: William Woodall <[email protected]>
(cherry picked from commit c834c24)

# Conflicts:
#	rclpy/test/test_service.py
#	rclpy/test/test_subscription.py
mergify bot pushed a commit that referenced this pull request Sep 17, 2025
…t and timer (#1496)

* Added set_on_new_response_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added set_on_new_request_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added set_on_new_message_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added set_on_reset_callback

Signed-off-by: Nadav Elkabets <[email protected]>

* Added type hints to pyi

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for subscription

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for timer

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for client

Signed-off-by: Nadav Elkabets <[email protected]>

* Added test for service

Signed-off-by: Nadav Elkabets <[email protected]>

* Fixed lint

Signed-off-by: Nadav Elkabets <[email protected]>

* Avoid throwing into c code

Signed-off-by: Nadav Elkabets <[email protected]>

* Print newline after logging exception

Co-authored-by: William Woodall <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>

* Improve logging and cleanup

Signed-off-by: Nadav Elkabets <[email protected]>

---------

Signed-off-by: Nadav Elkabets <[email protected]>
Signed-off-by: Nadav Elkabets <[email protected]>
Co-authored-by: William Woodall <[email protected]>
(cherry picked from commit c834c24)

# Conflicts:
#	rclpy/rclpy/impl/_rclpy_pybind11.pyi
#	rclpy/test/test_service.py
#	rclpy/test/test_subscription.py
#	rclpy/test/test_timer.py
@fujitatomoya
Copy link
Collaborator

@nadavelkabets we can backport this, so i requested kilted and jazzy for now. i did not create humble one, because the code base is really different.

ryantqiu pushed a commit to snorkel-marlin-repos/rclpy_1f45fb4a that referenced this pull request Oct 1, 2025
…t and timer

Original PR #1496 by nadavelkabets
Original: ros2/rclpy#1496
ryantqiu added a commit to snorkel-marlin-repos/rclpy_1f45fb4a that referenced this pull request Oct 1, 2025
…ription, service, client and timer

Merged from original PR #1496
Original: ros2/rclpy#1496
ryantqiu pushed a commit to snorkel-marlin-repos/rclpy_b7824799 that referenced this pull request Oct 1, 2025
…t and timer

Original PR #1496 by nadavelkabets
Original: ros2/rclpy#1496
ryantqiu added a commit to snorkel-marlin-repos/rclpy_b7824799 that referenced this pull request Oct 1, 2025
…ription, service, client and timer

Merged from original PR #1496
Original: ros2/rclpy#1496
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.

4 participants