launch_test does not return and shows ValueError: generator already executing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 155
- Forks
- 182
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
I am trying to run a test using launch_test but it shows "ValueError: generator already executing". In this case, the launch_test does not return. Therefore, I have to terminate the process by pressing Ctrl + C. Below is the complete info reported at terminal:
$ launch_test src/minimal_service/test/test_service_member_function.py
[INFO] [launch]: All log files can be found below /home/ravi/.ros/log/2022-08-01-19-42-08-016668-dell-96224
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [service_member_function-1]: process started with pid [96228]
test_srv_1 (test_service_member_function.TestMinimalServiceNode) ... ok
test_srv_1_exists (test_service_member_function.TestMinimalServiceNode) ... [WARN] [1659350528.358283962] [rcl.logging_rosout]: Publisher already registered for provided node name. If this is due to multiple nodes with the same name then all logs for that logger name will go out over the existing publisher. As soon as any node with that name is destructed it will unregister the publisher, preventing any further logs for that name from being published on the rosout topic.
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
ok
test_srv_2 (test_service_member_function.TestMinimalServiceNode) ... self._target(*self._args, **self._kwargs)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
executor.spin_once()
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
self._target(*self._args, **self._kwargs)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
return next(self._cb_iter)
ValueError: generator already executing
executor.spin_once()
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
return next(self._cb_iter)
ValueError: generator already executing
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[service_member_function-1] Traceback (most recent call last):
[service_member_function-1] File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/examples_rclpy_minimal_service/service_member_function", line 33, in <module>
[service_member_function-1] sys.exit(load_entry_point('examples-rclpy-minimal-service==0.9.4', 'console_scripts', 'service_member_function')())
[service_member_function-1] File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/python3.8/site-packages/examples_rclpy_minimal_service/service_member_function.py", line 31, in main
[service_member_function-1] rclpy.spin(node)
[service_member_function-1] File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
[service_member_function-1] executor.spin_once()
[service_member_function-1] File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
[service_member_function-1] handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
[service_member_function-1] File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
[service_member_function-1] return next(self._cb_iter)
[service_member_function-1] File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 588, in _wait_for_ready_callbacks
[service_member_function-1] wait_set.wait(timeout_nsec)
[service_member_function-1] KeyboardInterrupt
[ERROR] [service_member_function-1]: process has died [pid 96228, exit code -2, cmd '/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/examples_rclpy_minimal_service/service_member_function --ros-args -r __ns:=/'].
Processes under test stopped before tests completed
Process 'service_member_function-1' exited with -2
##### 'service_member_function-1' output #####
Traceback (most recent call last):
File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/examples_rclpy_minimal_service/service_member_function", line 33, in <module>
sys.exit(load_entry_point('examples-rclpy-minimal-service==0.9.4', 'console_scripts', 'service_member_function')())
File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/python3.8/site-packages/examples_rclpy_minimal_service/service_member_function.py", line 31, in main
rclpy.spin(node)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
executor.spin_once()
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
return next(self._cb_iter)
File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 588, in _wait_for_ready_callbacks
wait_set.wait(timeout_nsec)
KeyboardInterrupt
##############################################
Required Info:
- Operating System:
- Ubuntu 20.04.4 LTS
- Installation type:
- binaries
- DDS implementation:
- default
- Client library (if applicable):
- rclpy
Question
How to test all the services in my node?
Code
- test_service_member_function.py
from threading import Thread import unittest import launch import launch_ros import launch_testing import pytest import rclpy from std_srvs.srv import SetBool, Trigger from example_interfaces.srv import AddTwoInts as AddTwoI @pytest.mark.rostest def generate_test_description(): node = launch_ros.actions.Node( package='examples_rclpy_minimal_service', namespace='', executable='service_member_function', ) return ( launch.LaunchDescription( [ node, # Start tests right away - no need to wait for anything launch_testing.actions.ReadyToTest(), ] ), { 'minimal_service_node': node, }, ) class TestMinimalServiceNode(unittest.TestCase): @classmethod def setUpClass(cls): # Initialize the ROS context for the test node rclpy.init() @classmethod def tearDownClass(cls): # Shutdown the ROS context rclpy.shutdown() def setUp(self): # Create a ROS node for tests self.node = rclpy.create_node('test_minimal_service_node') # Creating service clients self.client_1 = self.node.create_client(AddTwoI, 'srv_1') self.client_2 = self.node.create_client(SetBool, 'srv_2') self.client_3 = self.node.create_client(Trigger, 'srv_3') self.assertTrue(self.client_1.wait_for_service(timeout_sec=5.0)) # Create a spin thread for synchronous service call self.spin_thread = Thread(target=rclpy.spin, args=(self.node,)) self.spin_thread.start() def tearDown(self): self.node.destroy_node() def test_srv_1_exists(self): self.assertTrue(self.client_1.wait_for_service(timeout_sec=5.0)) def test_srv_2_exists(self): self.assertTrue(self.client_2.wait_for_service(timeout_sec=5.0)) def test_srv_3_exists(self): self.assertTrue(self.client_3.wait_for_service(timeout_sec=5.0)) def test_srv_1(self): req = AddTwoI.Request(a=10, b=20) res = self.client_1.call(req) self.assertEqual(res.sum, 30) def test_srv_2(self): req = SetBool.Request(data=True) res = self.client_2.call(req) self.assertEqual(res.message, 'Hello from SetBool Service') def test_srv_3(self): req = Trigger.Request() res = self.client_3.call(req) self.assertEqual(res.message, 'Hello from Trigger Service') ``` - service_member_function.py
import rclpy from rclpy.node import Node from std_srvs.srv import SetBool, Trigger from example_interfaces.srv import AddTwoInts as AddTwoI class MinimalService(Node): def __init__(self): super().__init__('minimal_service') self.srv_1 = self.create_service(AddTwoI, 'srv_1', self.srv_1_cb) self.srv_2 = self.create_service(SetBool, 'srv_2', self.srv_2_cb) self.srv_3 = self.create_service(Trigger, 'srv_3', self.srv_3_cb) def srv_1_cb(self, req, res): res.sum = req.a + req.b return res def srv_2_cb(self, req, res): res.message = 'Hello from SetBool Service' return res def srv_3_cb(self, req, res): res.message = 'Hello from Trigger Service' return res def main(args=None): rclpy.init(args=args) node = MinimalService() rclpy.spin(node) rclpy.shutdown() if __name__ == '__main__': main()
Additional Info
Please note that all the services returns peacefully when called from terminal using ros2 service call .... Anyway, below is the workspace structure:
.
├── build
├── install
├── log
└── src
└── minimal_service
├── CHANGELOG.rst
├── examples_rclpy_minimal_service
│ ├── __init__.py
│ ├── service_member_function.py
│ └── service.py
├── package.xml
├── README.md
├── resource
│ └── examples_rclpy_minimal_service
├── setup.cfg
├── setup.py
└── test
├── test_copyright.py
├── test_flake8.py
├── test_pep257.py
└── test_service_member_function.py
The package minimal_service has been taken from ros2/examples.
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.
Research direction
Start with test/test_service_member_function.py and the launch_test invocation, then inspect the rclpy.spin calls and the service-client setup shown in the report. Reproduce the generator error with the listed service tests and determine the expected way to run all services without hanging; done means the test command completes without the ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100