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

Multiple SetEnvrionmentVariable override each other when launching multiple nodes #564

Open
fas2037 opened this issue Dec 1, 2021 · 2 comments
Labels
backlog question Further information is requested

Comments

@fas2037
Copy link

fas2037 commented Dec 1, 2021

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • Binaries
  • Version:
    • Galactic
  • DDS implementation:
    • Cyclone DDS

Steps to reproduce issue

Generate multiple nodes and call SetEnvironmentVariable in the LaunchDescription:

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import SetEnvironmentVariable


def generate_launch_description():
    return LaunchDescription([
        SetEnvironmentVariable(name='TEST', value='0'),
        Node(
            package="test_0",
            executable="test_0",
            name="test_0_node",
            output="screen",
        )
    ])
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import SetEnvironmentVariable


def generate_launch_description():
    return LaunchDescription([
        SetEnvironmentVariable(name='TEST', value='1),
        Node(
            package="test_1",
            executable="test_1",
            name="test_1_node",
            output="screen",
        )
    ])

Launch both nodes:

from ament_index_python.packages import get_package_share_directory

def generate_launch_description():

    nodes = ["test_0", "test_1"]
    includes = []

    for n in nodes:
        includes.append(launch.actions.IncludeLaunchDescription(launch.launch_description_sources.PythonLaunchDescriptionSource(get_package_share_directory(n) + '/launch/' + n + '_launch.py')))

    return launch.LaunchDescription(includes)

Expected behavior

When accessing the environmental variable in node 'test_0' it should have the value '0'.
When accessing the environmental variable in node 'test_1' it should have the value '1'.

Actual behavior

When accessing the environmental variable in node 'test_0' it has the value '1'.
When accessing the environmental variable in node 'test_1' it has the value '1'.

Additional information


@hidmic
Copy link
Contributor

hidmic commented Dec 7, 2021

@fas2037 SetEnvironmentVariable mutates the environment of launch itself (which is one, later propagated to its children). Even if that wasn't the case, it still wouldn't do what you expect since LaunchDescription instances do not execute anything and there's no lexical scoping to rely on.

For your specific use case, I'd suggest using the append_env argument of the Node class. If you'd like to see scoping improved, there have been some discussions in #501 and #313.

@hidmic hidmic added the question Further information is requested label Dec 7, 2021
@jacobperron
Copy link
Member

jacobperron commented Mar 4, 2022

I think #601 resolves this ticket. @fas2037 correct me if I'm wrong.

edit: Or at least it should be possible to do what you want using GroupAction with the includes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants