-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ros2/rclpy#1287 Signed-off-by: Tomoya Fujita <[email protected]>
- Loading branch information
1 parent
54a4a4f
commit 819313f
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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() |