Skip to content

Commit 88e81f3

Browse files
committed
Cleaner shutdown for mock GUI
1 parent d799fae commit 88e81f3

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

scripts/run_mock_dbc.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,30 @@
1717
# License for the specific language governing permissions and limitations
1818
# under the License.
1919

20-
import sys
21-
from functools import partial
22-
import signal
2320
import rclpy
2421
from rclpy.executors import MultiThreadedExecutor
25-
from rclpy.signals import SignalHandlerOptions
2622

2723
from drt_ur_gui.mock_dashboard_client import MockDashboardClient
2824

2925

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-
3826
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)
4128
multithread_exec = MultiThreadedExecutor()
29+
4230
mock_dbc = MockDashboardClient()
4331
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+
4633
try:
4734
multithread_exec.spin()
35+
except KeyboardInterrupt:
36+
pass
4837
except Exception as e:
4938
mock_dbc.get_logger().info(f"Executor spin error: {e}")
5039
finally:
5140
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
5441
mock_dbc.destroy_node()
5542
rclpy.try_shutdown()
5643
print("[MockDashboardClient Executable]: Completed cleanup, exiting...")
57-
sys.exit(0)
5844

5945

6046
if __name__ == "__main__":

0 commit comments

Comments
 (0)