Skip to content

Commit

Permalink
Exit with code 0 if ExternalShutdownException is raised (ros2#581)
Browse files Browse the repository at this point in the history
* Exit with code 0 if ExternalShutdownException is raised

This is an expected exception from the executor on a keyboard interrupt, so I don't think it should be an error.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron authored and cardboardcode committed Jan 23, 2023
1 parent 9928422 commit a1df329
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 48 deletions.
6 changes: 1 addition & 5 deletions demo_nodes_py/demo_nodes_py/services/add_two_ints_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

from example_interfaces.srv import AddTwoInts

import rclpy
Expand Down Expand Up @@ -41,10 +39,8 @@ def main(args=None):

try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
# Destroy the node explicitly
# (optional - Done automatically when node is garbage collected)
Expand Down
6 changes: 1 addition & 5 deletions demo_nodes_py/demo_nodes_py/topics/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
Expand All @@ -37,10 +35,8 @@ def main(args=None):
node = Listener()
try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
node.destroy_node()
rclpy.try_shutdown()
Expand Down
4 changes: 1 addition & 3 deletions demo_nodes_py/demo_nodes_py/topics/listener_qos.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def main(argv=sys.argv[1:]):
while rclpy.ok() and cycle_count < args.number_of_cycles:
rclpy.spin_once(node)
cycle_count += 1
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
node.destroy_node()
rclpy.try_shutdown()
Expand Down
6 changes: 1 addition & 5 deletions demo_nodes_py/demo_nodes_py/topics/listener_serialized.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
Expand Down Expand Up @@ -43,10 +41,8 @@ def main(args=None):

try:
rclpy.spin(serialized_subscriber)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
Expand Down
6 changes: 1 addition & 5 deletions demo_nodes_py/demo_nodes_py/topics/talker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
Expand Down Expand Up @@ -45,10 +43,8 @@ def main(args=None):

try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
node.destroy_node()
rclpy.try_shutdown()
Expand Down
4 changes: 1 addition & 3 deletions demo_nodes_py/demo_nodes_py/topics/talker_qos.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ def main(argv=sys.argv[1:]):
while rclpy.ok() and cycle_count < args.number_of_cycles:
rclpy.spin_once(node)
cycle_count += 1
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
node.destroy_node()
rclpy.try_shutdown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import sys

from quality_of_service_demo_py.common_nodes import Listener
from quality_of_service_demo_py.common_nodes import Talker
Expand Down Expand Up @@ -72,10 +71,8 @@ def main(args=None):
executor.add_node(talker)
try:
executor.spin()
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
rclpy.try_shutdown()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ def main(args=None):
try:
while talker.publish_count < num_msgs:
executor.spin_once()
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
return 1
finally:
rclpy.try_shutdown()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.executors import SingleThreadedExecutor
Expand Down Expand Up @@ -69,10 +67,8 @@ def main():

try:
executor.spin()
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
rclpy.try_shutdown()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
Expand Down Expand Up @@ -53,10 +51,8 @@ def main(args=None):
node = Listener()
try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
rclpy.try_shutdown()
node.destroy_node()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
Expand Down Expand Up @@ -61,10 +59,8 @@ def main(args=None):

try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except ExternalShutdownException:
sys.exit(1)
finally:
rclpy.try_shutdown()
node.destroy_node()
Expand Down

0 comments on commit a1df329

Please sign in to comment.