|
17 | 17 | # License for the specific language governing permissions and limitations |
18 | 18 | # under the License. |
19 | 19 |
|
20 | | -import sys |
21 | | -from functools import partial |
22 | | -import signal |
23 | 20 | import rclpy |
24 | 21 | from rclpy.executors import MultiThreadedExecutor |
25 | | -from rclpy.signals import SignalHandlerOptions |
26 | 22 |
|
27 | 23 | from drt_ur_gui.mock_dashboard_client import MockDashboardClient |
28 | 24 |
|
29 | 25 |
|
30 | | -def sigterm_handler(executor, node, sig, frame): |
31 | | - """ |
32 | | - Handler for SIGTERM signals. Triggers try_shutdown event on executor, forcing spin to stop. |
33 | | - """ |
34 | | - node.get_logger().warn("Received SIGTERM, shutting down mock dashboard client...") |
35 | | - executor.context.try_shutdown() |
36 | | - |
37 | | - |
38 | 26 | def main(args=None): |
39 | | - signal.signal(signal.SIGINT, signal.SIG_IGN) # block incoming SIGINT signals |
40 | | - rclpy.init(args=args, signal_handler_options=SignalHandlerOptions.NO) # tell ros2 to let us handle all signals |
| 27 | + rclpy.init(args=args) |
41 | 28 | multithread_exec = MultiThreadedExecutor() |
| 29 | + |
42 | 30 | mock_dbc = MockDashboardClient() |
43 | 31 | multithread_exec.add_node(mock_dbc) |
44 | | - signal_handler = partial(sigterm_handler, multithread_exec, mock_dbc) # set up signal handler lambda function |
45 | | - signal.signal(signal.SIGTERM, signal_handler) # set SIGTERM signals to trigger the signal handler function |
| 32 | + |
46 | 33 | try: |
47 | 34 | multithread_exec.spin() |
| 35 | + except KeyboardInterrupt: |
| 36 | + pass |
48 | 37 | except Exception as e: |
49 | 38 | mock_dbc.get_logger().info(f"Executor spin error: {e}") |
50 | 39 | finally: |
51 | 40 | mock_dbc.get_logger().info("Cleaning up mock dashboard client...") |
52 | | - # Normally we wait for executor shutdown here, but we're relying on sys.exit(0) |
53 | | - # to kill running threads faster to avoid a SIGKILL escalation |
54 | 41 | mock_dbc.destroy_node() |
55 | 42 | rclpy.try_shutdown() |
56 | 43 | print("[MockDashboardClient Executable]: Completed cleanup, exiting...") |
57 | | - sys.exit(0) |
58 | 44 |
|
59 | 45 |
|
60 | 46 | if __name__ == "__main__": |
|
0 commit comments