Feature Request: LaunchService wrapper for easy non-blocking launch and shutdown
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 155
- Forks
- 182
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
Feature request
Feature description
LaunchService has puzzled many people as to how to properly launch a LaunchDescription without blocking the main thread:
https://github.com/ros2/launch/pull/210
https://answers.ros.org/question/321118/ros2-nodes-occasionally-dying-using-launchservice-in-a-subprocess/
https://github.com/ros2/launch/issues/126
So I propose either adding a start() function to LaunchService, or a new wrapper class, that spawns a daemon process to run the async launch loop, like this:
import asyncio
import multiprocessing
from launch import LaunchDescription, LaunchService
class Ros2LaunchParent:
def start(self, launch_description: LaunchDescription):
self._stop_event = multiprocessing.Event()
self._process = multiprocessing.Process(target=self._run_process, args=(self._stop_event, launch_description), daemon=True)
self._process.start()
def shutdown(self):
self._stop_event.set()
self._process.join()
def _run_process(self, stop_event, launch_description):
loop = asyncio.get_event_loop()
launch_service = LaunchService()
launch_service.include_launch_description(launch_description)
launch_task = loop.create_task(launch_service.run_async())
loop.run_until_complete(loop.run_in_executor(None, stop_event.wait))
if not launch_task.done():
asyncio.ensure_future(launch_service.shutdown(), loop=loop)
loop.run_until_complete(launch_task)
Implementation considerations
Besides launching a LaunchDescription, it would be better if there is another mode of launching an individual node and get its PID to operate the process, just like ROS1 does.
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 by reviewing the LaunchService entry points named in the issue: include_launch_description(), run_async(), and shutdown(), along with the linked discussion and prior issue. Determine whether the intended scope is a start() API or a wrapper process, and whether individual-node PID control is included. Done should include a decided interface for non-blocking launch and clean shutdown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100