[ros-users] [Discourse.ros.org] How to shutdown and reinitialize a publisher node in ROS 2
William Woodall
ros.discourse at gmail.com
Sat Mar 3 00:12:34 UTC 2018
Just for fun I did this last iteration in Python a well, which works:
```python
import sys
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
def main():
msg = String()
i = 0
while True:
rclpy.init()
node = Node('talker')
pub = node.create_publisher(String, 'chatter')
msg.data = 'Hello World: {0}'.format(i)
i += 1
node.get_logger().info('Publishing: "{0}"'.format(msg.data))
pub.publish(msg)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
```
---
[Visit Topic](https://discourse.ros.org/t/how-to-shutdown-and-reinitialize-a-publisher-node-in-ros-2/4090/3) or reply to this email to respond.
More information about the ros-users
mailing list