Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async run method to LaunchService #210

Merged
merged 3 commits into from
Aug 13, 2019
Merged

Conversation

hidmic
Copy link
Contributor

@hidmic hidmic commented Mar 20, 2019

This pull request enables asynchronous launch runs. This popped up in a discussion I had with @wjwwood as an alternative to pushing a launch run to a background thread (see #126), which is unsupported (explicitly after these changes).

Consider the following snippet for an example of the new async API:

#!/usr/bin/env python3

import asyncio
import osrf_pycommon

from launch import LaunchDescription
from launch import LaunchService
import launch_ros.actions


def main():
    ld = LaunchDescription([
        launch_ros.actions.Node(
            package='demo_nodes_cpp',
            node_executable='listener',
            output='screen'
        ),
    ])

    loop = osrf_pycommon.process_utils.get_loop()
    ls = LaunchService(debug=True)
    ls.include_launch_description(ld)
    print(">>> Do some work")
    launch_task = loop.create_task(ls.run_async())
    print(">>> Sleep time!")
    loop.run_until_complete(asyncio.sleep(5, loop=loop))
    print(">>> I'm awake!")
    if not launch_task.done():
        print(">>> Wrapping up")
        asyncio.ensure_future(ls.shutdown(), loop=loop)
        loop.run_until_complete(launch_task)
    print(">>> Bye bye")
    return launch_task.result()


if __name__=="__main__":
    main()

Hopefully, this will simplify launch based fixtures for testing.

cc @pbaughman for awareness.

@hidmic hidmic added the in review Waiting for review (Kanban column) label Mar 20, 2019
@hidmic hidmic requested a review from wjwwood March 20, 2019 19:45
@hidmic hidmic changed the title Add run_async coroutine to LaunchService. Add run_async coroutine to LaunchService Mar 20, 2019
@hidmic hidmic changed the title Add run_async coroutine to LaunchService Add async run method to LaunchService Mar 20, 2019
@hidmic hidmic force-pushed the hidmic/async-launch-run branch from ce300f6 to e6e53b9 Compare April 4, 2019 15:12
@hidmic
Copy link
Contributor Author

hidmic commented Apr 4, 2019

Rebased to solve merge conflicts.

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes lgtm.

In general, I think this is a good direction to go in, even if we don't end up using it in the testing stuff.

I am however concerned about regressions, because this code is so tricky (the current implementation included), so I'd be in favor of merging this, but with the idea that follow up work is likely.

Do you want to move forward with getting this merged, or do you only want to merge it if we're going to be using it with the testing framework.

launch/test/launch/test_launch_service.py Outdated Show resolved Hide resolved
launch/test/launch/test_launch_service.py Outdated Show resolved Hide resolved
@hidmic
Copy link
Contributor Author

hidmic commented Apr 9, 2019

I am however concerned about regressions, because this code is so tricky (the current implementation included)

I share your concerns.

Do you want to move forward with getting this merged, or do you only want to merge it if we're going to be using it with the testing framework.

There's not point in having this PR collecting dust IMHO. If we regard this as a good addition, I think we should move forward and endure the pain, regardless of what happens with launch_testing. If at some point it comes down to having a stable release or not, we can always revert the patch.

@hidmic
Copy link
Contributor Author

hidmic commented Apr 9, 2019

CI (up to test_communication, test_rclcpp):

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

hidmic added 2 commits August 7, 2019 11:23
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic force-pushed the hidmic/async-launch-run branch from fe6c549 to d18ddea Compare August 7, 2019 14:24
@hidmic
Copy link
Contributor Author

hidmic commented Aug 7, 2019

Hmm, Windows has failing tests, but the same show up in an unrelated CI run (ros2/rcl#477). I'll check if the issue happens on master already.

In the meantime, @wjwwood @dirk-thomas PTAL.

Copy link
Member

@ivanpauno ivanpauno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some minimal comments, otherwise it looks great!

launch/launch/launch_service.py Outdated Show resolved Hide resolved
launch/launch/launch_service.py Show resolved Hide resolved
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic
Copy link
Contributor Author

hidmic commented Aug 13, 2019

Alright, going in.

@hidmic hidmic merged commit 884e14e into master Aug 13, 2019
@delete-merged-branch delete-merged-branch bot deleted the hidmic/async-launch-run branch August 13, 2019 20:31
@hidmic
Copy link
Contributor Author

hidmic commented Aug 13, 2019

I'll keep an eye on this one, just in case nightlies go red (for some unexpected reason).

piraka9011 pushed a commit to aws-ros-dev/launch that referenced this pull request Aug 16, 2019
* Add run_async coroutine to LaunchService.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Address peer review comments.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Remove duplicate thread check.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in review Waiting for review (Kanban column)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants