Skip to content

Commit

Permalink
Switch to using an rclpy context manager. (#787)
Browse files Browse the repository at this point in the history
This still manages the lifetime of rclpy, but uses
less code to do so.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Jul 9, 2024
1 parent c4c8033 commit 600119f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
5 changes: 1 addition & 4 deletions launch_pytest/test/launch_pytest/examples/check_node_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ def generate_test_description():

@pytest.mark.launch(fixture=generate_test_description)
def test_check_if_msgs_published():
rclpy.init()
try:
with rclpy.init():
node = MakeTestNode('test_node')
node.start_subscriber()
msgs_received_flag = node.msg_event_object.wait(timeout=5.0)
assert msgs_received_flag, 'Did not receive msgs !'
finally:
rclpy.shutdown()


class MakeTestNode(Node):
Expand Down
14 changes: 5 additions & 9 deletions launch_pytest/test/launch_pytest/examples/executables/talker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node

from std_msgs.msg import String
Expand All @@ -34,17 +35,12 @@ def callback(self):


def main(args=None):
rclpy.init(args=args)

node = Talker()

try:
rclpy.spin(node)
except KeyboardInterrupt:
with rclpy.init(args=args):
node = Talker()
rclpy.spin(node)
except (KeyboardInterrupt, ExternalShutdownException):
pass
finally:
node.destroy_node()
rclpy.shutdown()


if __name__ == '__main__':
Expand Down

0 comments on commit 600119f

Please sign in to comment.