未验证 提交 f297a332 编写于 作者: L Leo Chen 提交者: GitHub

Dev/fix init flags (#23465)

* fix init_gflags with 'python -c', test=develop

* add test, test=develop

* use sys.executable instead of python, test=develop

* keep dummy, test=develop
上级 6a23850a
......@@ -53,6 +53,11 @@ std::once_flag glog_warning_once_flag;
void InitGflags(std::vector<std::string> argv) {
std::call_once(gflags_init_flag, [&]() {
FLAGS_logtostderr = true;
// NOTE(zhiqiu): dummy is needed, since the function
// ParseNewCommandLineFlags in gflags.cc starts processing
// commandline strings from idx 1.
// The reason is, it assumes that the first one (idx 0) is
// the filename of executable file.
argv.insert(argv.begin(), "dummy");
int argc = argv.size();
char **arr = new char *[argv.size()];
......@@ -62,8 +67,10 @@ void InitGflags(std::vector<std::string> argv) {
line += argv[i];
line += ' ';
}
VLOG(1) << "Before Parse: argc is " << argc
<< ", Init commandline: " << line;
google::ParseCommandLineFlags(&argc, &arr, true);
VLOG(1) << "Init commandline: " << line;
VLOG(1) << "After Parse: argc is " << argc;
});
}
......
......@@ -214,8 +214,7 @@ def __bootstrap__():
'cudnn_batchnorm_spatial_persistent', 'gpu_allocator_retry_time',
'local_exe_sub_scope_limit', 'gpu_memory_limit_mb'
]
core.init_gflags([sys.argv[0]] +
["--tryfromenv=" + ",".join(read_env_flags)])
core.init_gflags(["--tryfromenv=" + ",".join(read_env_flags)])
core.init_glog(sys.argv[0])
# don't init_p2p when in unittest to save time.
core.init_devices(not in_test)
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import os
import sys
class TestRunFluidByModule(unittest.TestCase):
def test_module(self):
print(sys.executable)
res = os.system(sys.executable + ' -m "paddle.fluid.reader"')
self.assertEqual(res, 0) # 0 means status OK
class TestRunFluidByCommand(unittest.TestCase):
def test_command(self):
res = os.system(sys.executable + ' -c "import paddle.fluid"')
self.assertEqual(res, 0) # 0 means status OK
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册