Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Of course I waited a while to post this after not finding an answer and now I have it. I just needed to use a multi-threaded executor and spin that instead of spinning the nodes individually:

import threading
import rclpy
rclpy.init()
node = rclpy.create_node('simple_node')
node2 = rclpy.create_node('simpler_node')
executor = rclpy.executors.MultiThreadedExecutor()
executor.add_node(node)
executor.add_node(node2)
# Spin in a separate thread
executor_thread = threading.Thread(target=executor.spin, daemon=True)
executor_thread.start()
rate = node.create_rate(2)
try:
    while rclpy.ok():
        print('Help me body, you are my only hope')
        rate.sleep()
except KeyboardInterrupt:
    pass
rclpy.shutdown()
executor_thread.join()