Skip to content

Commit

Permalink
context.on_shutdown is never called
Browse files Browse the repository at this point in the history
  ros2/rclpy#1287

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed May 23, 2024
1 parent 54a4a4f commit 819313f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions prover_rclpy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'rclpy_1163_sub = src.rclpy_1163_sub:main',
'rclpy_1199 = src.rclpy_1199:main',
'rclpy_1273 = src.rclpy_1273:main',
'rclpy_1287 = src.rclpy_1287:main',
'ros2cli_818 = src.ros2cli_818:main',
'ros2cli_862 = src.ros2cli_862:main',
'ros2cli_885 = src.ros2cli_885:main',
Expand Down
43 changes: 43 additions & 0 deletions prover_rclpy/src/rclpy_1287.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

import signal
import sys

import rclpy
import rclpy.node

from rclpy.executors import ExternalShutdownException
from rclpy.signals import SignalHandlerOptions

def shutdown_handler():
print("exit")

def main(args=None):
def signal_handler(sig, frame):
# this handler should be called before deferred signal handler
print("signal receive\n")
rclpy.shutdown()
#rclpy.try_shutdown()
signal.signal(signal.SIGINT, signal_handler)

rclpy.init(args=args)
#rclpy.init(args=args, signal_handler_options=SignalHandlerOptions.NO)

try:
node = rclpy.create_node("test_node")

node.context.on_shutdown(shutdown_handler)
rclpy.get_default_context().on_shutdown(shutdown_handler)

rclpy.spin(node)
except KeyboardInterrupt:
pass
except ExternalShutdownException:
sys.exit(1)

#rclpy.shutdown()
rclpy.try_shutdown()


if __name__ == "__main__":
main()

0 comments on commit 819313f

Please sign in to comment.