You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
@fas2037SetEnvironmentVariable 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.
Bug report
Required Info:
Steps to reproduce issue
Generate multiple nodes and call SetEnvironmentVariable in the LaunchDescription:
Launch both nodes:
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
The text was updated successfully, but these errors were encountered: