-
Notifications
You must be signed in to change notification settings - Fork 295
Explicitly add DLL directories for Windows before importing #558
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e561a30
241a02c
4f1676c
a795304
4f5cc27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,20 @@ | |
|
|
||
|
|
||
| def _import(name): | ||
| dll_dir_handles = [] | ||
| try: | ||
| return importlib.import_module(name, package='rclpy') | ||
| # New in Python 3.8: on Windows we should call 'add_dll_directory()' for directories | ||
| # containing DLLs we depend on. | ||
| # https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew | ||
| if os.name == 'nt': | ||
| path_env = os.environ['PATH'].split(';') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a reason why Python chose to not use all paths in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Message packages should probably contain their own logic to ensure their path is added too.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What I gather from the issue[1] is that where DLLs are loaded from was not consistent before Python 3.8 (e.g. in general, you couldn't assume that PATH was ever searched for DLLs; it was using the process default ordering[2]), which has some security implications[3]. The change in Python 3.8 forces a consistent search order. The reason to not include [1] https://bugs.python.org/issue36085
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you're right. |
||
| for prefix_path in path_env: | ||
| if os.path.exists(prefix_path): | ||
| dll_dir_handles.append(os.add_dll_directory(prefix_path)) | ||
|
|
||
| imported_module = importlib.import_module(name, package='rclpy') | ||
|
|
||
| return imported_module | ||
| except ImportError as e: | ||
| if e.path is not None and os.path.isfile(e.path): | ||
| e.msg += \ | ||
|
|
@@ -27,3 +39,6 @@ def _import(name): | |
| (e.path, 'https://index.ros.org/doc/ros2/Troubleshooting/' | ||
| '#import-failing-even-with-library-present-on-the-system') | ||
| raise | ||
| finally: | ||
| for handle in dll_dir_handles: | ||
| handle.close() | ||
Uh oh!
There was an error while loading. Please reload this page.