From fc43909e043409f758c31e2710f4142717eab882 Mon Sep 17 00:00:00 2001 From: hutuxian Date: Wed, 13 May 2020 19:14:43 +0800 Subject: [PATCH] Cherry-pick #23907 & #24223 (#24465) * remove print statement to make code clean(#23907) * Try to fix UT Random Fail (#24223) --- paddle/fluid/framework/CMakeLists.txt | 2 +- python/paddle/fluid/trainer_desc.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index d6cce25401..361f25d09e 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -157,7 +157,7 @@ if(WITH_PYTHON) #Generate an empty \ #__init__.py to make framework_py_proto as a valid python module. add_custom_target(framework_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch __init__.py) - add_dependencies(framework_py_proto framework_py_proto_init) + add_dependencies(framework_py_proto framework_py_proto_init trainer_py_proto) if (NOT WIN32) add_custom_command(TARGET framework_py_proto POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${PADDLE_BINARY_DIR}/python/paddle/fluid/proto diff --git a/python/paddle/fluid/trainer_desc.py b/python/paddle/fluid/trainer_desc.py index f323439c55..2a206e7fa2 100644 --- a/python/paddle/fluid/trainer_desc.py +++ b/python/paddle/fluid/trainer_desc.py @@ -33,15 +33,11 @@ class TrainerDesc(object): # Workaround for relative import in protobuf under python3 # TODO: should be fixed cur_path = os.path.dirname(__file__) - sys.path.append(cur_path) - sys.path.append(cur_path + "/proto") - - # Just for fix random UT fail, will be deleted soon - print("cur_path: ", cur_path) - print("sys.path: ", sys.path) - if os.path.isdir(cur_path + "/proto"): - print("[listdir]") - print(os.listdir(cur_path + "/proto")) + if cur_path not in sys.path: + sys.path.append(cur_path) + if cur_path + "/proto" not in sys.path: + sys.path.append(cur_path + "/proto") + from proto import trainer_desc_pb2 self.proto_desc = trainer_desc_pb2.TrainerDesc() import multiprocessing as mp -- GitLab