From 2497f4392fe60f4c72e9b7ff5de9b8b6117aacac Mon Sep 17 00:00:00 2001 From: Wojciech Uss Date: Wed, 17 Feb 2021 22:37:17 -0800 Subject: [PATCH] Handle missing symlink method on Windows (#31006) --- .../fluid/tests/unittests/test_static_save_load.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_static_save_load.py b/python/paddle/fluid/tests/unittests/test_static_save_load.py index ca66aa47266..f182e71cf0d 100644 --- a/python/paddle/fluid/tests/unittests/test_static_save_load.py +++ b/python/paddle/fluid/tests/unittests/test_static_save_load.py @@ -1276,11 +1276,11 @@ class TestProgramStateOldSave(unittest.TestCase): # case 2: load with no need file def symlink_force(target, link_name): try: - os.symlink(target, link_name) + self.create_symlink(target, link_name) except OSError as e: if e.errno == errno.EEXIST: os.remove(link_name) - os.symlink(target, link_name) + self.create_symlink(target, link_name) else: raise e @@ -1304,6 +1304,14 @@ class TestProgramStateOldSave(unittest.TestCase): for k, v in load_state.items(): self.assertTrue(np.array_equal(base_map[k], v)) + def create_symlink(self, target, link_name): + try: + os.symlink(target, link_name) + except AttributeError: + import ctypes + kernel_dll = ctypes.windll.LoadLibrary("kernel32.dll") + kernel_dll.CreateSymbolicLinkA(target, link_name, 0) + def check_in_static(self, main_program, base_map): for var in main_program.list_vars(): if isinstance(var, framework.Parameter) or var.persistable: -- GitLab