Python demo_nodes_py talker.py contains bug in usage of rlcpy.init
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start with demo_nodes_py/demo_nodes_py/topics/talker.py line 41 and listener.py line 34, then compare their rclpy.init usage with the documented return value. Verify both demo nodes start without the reported context-manager exception and continue operating as expected.
Written by the indexing model from the issue text.
Description
Generated by Generative AI
No
Operating System:
Linux 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
ROS version or commit hash:
jazzy
RMW implementation (if applicable):
rmw_fastrtps_cpp
RMW Configuration (if applicable):
The initialization pattern:
with rclpy.init(args=args):
in https://github.com/ros2/demos/blob/rolling/demo_nodes_py/demo_nodes_py/topics/talker.py (line 41) and https://github.com/ros2/demos/blob/rolling/demo_nodes_py/demo_nodes_py/topics/listener.py (line 34) fails
with following error message:
with rclpy.init(args=args):
TypeError: 'NoneType' object does not support the context manager protocol
which is logical, because rclpy.init return None according to the documentation (https://docs.ros.org/en/iron/p/rclpy/api/init_shutdown.html#rclpy.init)
If one uses the initialization sequence:
rclpy.init(args=args)
node = NodeClass() #i.e. Talker or Listener
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
, then the node functions properly
One could consider as well following sequence:
try:
rclpy.init(args=args)
node = NodeClass() #i.e. Talker or Listener
try:
rclpy.spin(node)
finally:
node.destroy_node()
rclpy.shutdown()
except (KeyboardInterrupt, ExternalShutdownException):
pass
which is close in spirit to one used in demo classes, and does not print stack trace on keyboard interrupt
Client library (if applicable):
No response
'ros2 doctor --report' output
ros2 doctor --report
<COPY OUTPUT HERE>
Steps to reproduce issue
- Create a package with publisher and subscriber node, using code from https://github.com/ros2/demos/blob/rolling/demo_nodes_py/demo_nodes_py/topics/talker.py as a base
- Add entry points to setup.py for newly created nodes
- try to get node to run
Expected behavior
No exception when starting a talker or listener node
Actual behavior
The node starts and starts listening to the topic
Additional information
No response
- Dominant language
- C++
- Stars
- 653
- Forks
- 359
- Avg merge
- 6d 20h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ros2/demos
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
enhancement good first issue
-
enhancement good first issue
-
enhancement good first issue
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·