From 35e013dc11dc9a13fb5a6388f69da21b26c5ac94 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 21 Oct 2019 14:22:55 -0300 Subject: [PATCH 1/2] Import rosbag2_transport Python module on demand. Signed-off-by: Michel Hidalgo --- ros2bag/ros2bag/verb/info.py | 4 +--- ros2bag/ros2bag/verb/play.py | 3 +-- ros2bag/ros2bag/verb/record.py | 5 ++++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py index 19a27df4bc..240e339127 100644 --- a/ros2bag/ros2bag/verb/info.py +++ b/ros2bag/ros2bag/verb/info.py @@ -16,8 +16,6 @@ from ros2bag.verb import VerbExtension -from rosbag2_transport import rosbag2_transport_py - class InfoVerb(VerbExtension): """ros2 bag info.""" @@ -34,5 +32,5 @@ def main(self, *, args): # noqa: D102 bag_file = args.bag_file if not os.path.exists(bag_file): return "[ERROR] [ros2bag]: bag file '{}' does not exist!".format(bag_file) - + from rosbag2_transport import rosbag2_transport_py rosbag2_transport_py.info(uri=bag_file, storage_id=args.storage) diff --git a/ros2bag/ros2bag/verb/play.py b/ros2bag/ros2bag/verb/play.py index 3e6500495b..2339133367 100644 --- a/ros2bag/ros2bag/verb/play.py +++ b/ros2bag/ros2bag/verb/play.py @@ -16,7 +16,6 @@ from ros2bag.verb import VerbExtension from ros2cli.node import NODE_NAME_PREFIX -from rosbag2_transport import rosbag2_transport_py class PlayVerb(VerbExtension): @@ -38,7 +37,7 @@ def main(self, *, args): # noqa: D102 bag_file = args.bag_file if not os.path.exists(bag_file): return "[ERROR] [ros2bag] bag file '{}' does not exist!".format(bag_file) - + from rosbag2_transport import rosbag2_transport_py rosbag2_transport_py.play( uri=bag_file, storage_id=args.storage, diff --git a/ros2bag/ros2bag/verb/record.py b/ros2bag/ros2bag/verb/record.py index c0d0ea27e0..3e013b079a 100644 --- a/ros2bag/ros2bag/verb/record.py +++ b/ros2bag/ros2bag/verb/record.py @@ -20,7 +20,6 @@ from ros2cli.node.strategy import NodeStrategy from ros2cli.node.strategy import add_arguments from ros2cli.node import NODE_NAME_PREFIX -from rosbag2_transport import rosbag2_transport_py class RecordVerb(VerbExtension): @@ -73,6 +72,8 @@ def main(self, *, args): # noqa: D102 self.create_bag_directory(uri) if args.all: + from rosbag2_transport import rosbag2_transport_py + rosbag2_transport_py.record( uri=uri, storage_id=args.storage, @@ -82,6 +83,8 @@ def main(self, *, args): # noqa: D102 no_discovery=args.no_discovery, polling_interval=args.polling_interval) elif args.topics and len(args.topics) > 0: + from rosbag2_transport import rosbag2_transport_py + rosbag2_transport_py.record( uri=uri, storage_id=args.storage, From 3b2c58aaf0f1e624807326857b1a1accf326eb15 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 21 Oct 2019 15:55:09 -0300 Subject: [PATCH 2/2] Add implementation notes to explain on demand imports. Signed-off-by: Michel Hidalgo --- ros2bag/ros2bag/verb/info.py | 5 +++++ ros2bag/ros2bag/verb/play.py | 5 +++++ ros2bag/ros2bag/verb/record.py | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py index 240e339127..210ac76781 100644 --- a/ros2bag/ros2bag/verb/info.py +++ b/ros2bag/ros2bag/verb/info.py @@ -32,5 +32,10 @@ def main(self, *, args): # noqa: D102 bag_file = args.bag_file if not os.path.exists(bag_file): return "[ERROR] [ros2bag]: bag file '{}' does not exist!".format(bag_file) + # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups + # combined with constrained environments (as imposed by colcon test) + # may result in DLL loading failures when attempting to import a C + # extension. Therefore, do not import rosbag2_transport at the module + # level but on demand, right before first use. from rosbag2_transport import rosbag2_transport_py rosbag2_transport_py.info(uri=bag_file, storage_id=args.storage) diff --git a/ros2bag/ros2bag/verb/play.py b/ros2bag/ros2bag/verb/play.py index 2339133367..e5dd73604c 100644 --- a/ros2bag/ros2bag/verb/play.py +++ b/ros2bag/ros2bag/verb/play.py @@ -37,6 +37,11 @@ def main(self, *, args): # noqa: D102 bag_file = args.bag_file if not os.path.exists(bag_file): return "[ERROR] [ros2bag] bag file '{}' does not exist!".format(bag_file) + # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups + # combined with constrained environments (as imposed by colcon test) + # may result in DLL loading failures when attempting to import a C + # extension. Therefore, do not import rosbag2_transport at the module + # level but on demand, right before first use. from rosbag2_transport import rosbag2_transport_py rosbag2_transport_py.play( uri=bag_file, diff --git a/ros2bag/ros2bag/verb/record.py b/ros2bag/ros2bag/verb/record.py index 3e013b079a..fd6d7135b7 100644 --- a/ros2bag/ros2bag/verb/record.py +++ b/ros2bag/ros2bag/verb/record.py @@ -72,6 +72,11 @@ def main(self, *, args): # noqa: D102 self.create_bag_directory(uri) if args.all: + # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups + # combined with constrained environments (as imposed by colcon test) + # may result in DLL loading failures when attempting to import a C + # extension. Therefore, do not import rosbag2_transport at the module + # level but on demand, right before first use. from rosbag2_transport import rosbag2_transport_py rosbag2_transport_py.record( @@ -83,6 +88,11 @@ def main(self, *, args): # noqa: D102 no_discovery=args.no_discovery, polling_interval=args.polling_interval) elif args.topics and len(args.topics) > 0: + # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups + # combined with constrained environments (as imposed by colcon test) + # may result in DLL loading failures when attempting to import a C + # extension. Therefore, do not import rosbag2_transport at the module + # level but on demand, right before first use. from rosbag2_transport import rosbag2_transport_py rosbag2_transport_py.record(