ros-visualization / rqt

63 stars 71 forks source link

RQT Python plugin exception on signal receipt #279

Closed ciandonovan closed 1 year ago

ciandonovan commented 2 years ago

System Information

Problem Description

All RQT Python plugins throw an exception on receipt of an interrupt signal (SIGINT).

rqt -v
...
^C[INFO] [1662392294.509266142] [rclcpp]: signal_handler(signum=2)
rclpy.shutdown() was called before QThread.quit()

sigint_handler()
MainWindow.closeEvent()
PluginManager.save_settings()
PluginManager.save_settings() completed
PluginManager.close_application() completed
Shutting down RosPyPluginProvider
Quit called on RclpySpinner
Traceback (most recent call last):
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/plugin_manager.py", line 456, in close_application
    self._save_settings(
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/plugin_manager.py", line 434, in _save_settings
    callback()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/plugin_manager.py", line 462, in _close_application_save_callback
    self._close_application_shutdown_plugins()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/plugin_manager.py", line 472, in _close_application_shutdown_plugins
    self._close_application_shutdown_callback()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/plugin_manager.py", line 480, in _close_application_shutdown_callback
    self._close_application_signal()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/plugin_manager.py", line 483, in _close_application_signal
    self._plugin_provider.shutdown()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/composite_plugin_provider.py", line 87, in shutdown
    plugin_provider.shutdown()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/qt_gui/composite_plugin_provider.py", line 87, in shutdown
    plugin_provider.shutdown()
  File "/opt/ros/humble/lib/python3.10/site-packages/rqt_gui_py/ros_py_plugin_provider.py", line 62, in shutdown
    self._destroy_node()
  File "/opt/ros/humble/lib/python3.10/site-packages/rqt_gui_py/ros_py_plugin_provider.py", line 89, in _destroy_node
    rclpy.shutdown()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 126, in shutdown
    _shutdown(context=context)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/utilities.py", line 58, in shutdown
    return context.shutdown()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/context.py", line 102, in shutdown
    self.__context.shutdown()
rclpy._rclpy_pybind11.RCLError: failed to shutdown: rcl_shutdown already called on the given context, at ./src/rcl/init.c:241
Aborted (core dumped)

This behavior can not be reproduced on ROS2 Foxy, and seems to be a regression introduced in either Galactic or Humble.

Seemingly the code handling the RQT plugin calls rclpy.shutdown(), despite the fact that this function will also always be called later by RQT, where it then complains that the function has already been called.

rclpy.shutdown() was called before QThread.quit()

The above line also suggests that the order in which the node is torn down is incorrect when handling signals in respect to QT. Interestingly that warning isn't thrown when an RQT plugin is closed through its desktop window close button.

https://github.com/ros-visualization/rqt/blob/6cf57076b8501264497fd7355997335b3d05d511/rqt_gui_py/src/rqt_gui_py/ros_py_plugin_provider.py#L89

Removing this line prevents rclpy.shutdown() from being called twice and crashing, however it stills complains about being called before QThread.quit()

ciandonovan commented 2 years ago

This only happens with Python and not C++ plugins, and only when the Python plugin is loaded in RQT. With RQT running and no plugin loaded, it responds to a SIGINT correctly.

However, RQT alone, or with either Python or C++ plugins loaded, will never respond to a SIGTERM, but will log it.

[INFO] [1662406460.729305639] [rclcpp]: signal_handler(signum=15)

ymd-stella commented 1 year ago

I think it has already been fixed in #291.

clalancette commented 1 year ago

Yes, you are right. I'm going to go ahead and close this one out, thanks!