未验证 提交 a9f9fbad 编写于 作者: Y Yu Yang 提交者: GitHub

Merge pull request #10832 from typhoonzero/fix_server_port_file_conflict

fix dist test
...@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include <stdio.h> // for removing the port file
#include <fstream> #include <fstream>
#include <ostream> #include <ostream>
#include <thread> // NOLINT #include <thread> // NOLINT
...@@ -77,12 +78,14 @@ ListenAndServOp::ListenAndServOp(const std::string &type, ...@@ -77,12 +78,14 @@ ListenAndServOp::ListenAndServOp(const std::string &type,
void ListenAndServOp::Stop() { void ListenAndServOp::Stop() {
rpc_service_->Push(LISTEN_TERMINATE_MESSAGE); rpc_service_->Push(LISTEN_TERMINATE_MESSAGE);
server_thread_->join(); server_thread_->join();
auto file_path = string::Sprintf("/tmp/paddle.%d.port", ::getpid());
remove(file_path.c_str());
} }
void ListenAndServOp::SavePort(const std::string &file_path) const { void ListenAndServOp::SavePort() const {
// NOTE: default write file to /tmp/paddle.selected_port // NOTE: default write file to /tmp/paddle.selected_port
selected_port_ = rpc_service_->GetSelectedPort(); selected_port_ = rpc_service_->GetSelectedPort();
auto file_path = string::Sprintf("/tmp/paddle.%d.port", ::getpid());
std::ofstream port_file; std::ofstream port_file;
port_file.open(file_path); port_file.open(file_path);
port_file << selected_port_.load(); port_file << selected_port_.load();
...@@ -331,7 +334,7 @@ void ListenAndServOp::RunImpl(const framework::Scope &scope, ...@@ -331,7 +334,7 @@ void ListenAndServOp::RunImpl(const framework::Scope &scope,
// Write to a file of server selected port for python use. // Write to a file of server selected port for python use.
std::string file_path = string::Sprintf("/tmp/paddle.%d.selected_port", std::string file_path = string::Sprintf("/tmp/paddle.%d.selected_port",
static_cast<int>(::getpid())); static_cast<int>(::getpid()));
SavePort(file_path); SavePort();
if (sync_mode) { if (sync_mode) {
RunSyncLoop(&executor, program, &recv_scope, prefetch_block); RunSyncLoop(&executor, program, &recv_scope, prefetch_block);
} else { } else {
......
...@@ -48,8 +48,7 @@ class ListenAndServOp : public framework::OperatorBase { ...@@ -48,8 +48,7 @@ class ListenAndServOp : public framework::OperatorBase {
void RunAsyncLoop(framework::Executor* executor, void RunAsyncLoop(framework::Executor* executor,
framework::ProgramDesc* program) const; framework::ProgramDesc* program) const;
void SavePort( void SavePort() const;
const std::string& file_path = "/tmp/paddle.selected_port") const;
void WaitServerReady(); void WaitServerReady();
......
...@@ -34,7 +34,7 @@ class TestSendOp(unittest.TestCase): ...@@ -34,7 +34,7 @@ class TestSendOp(unittest.TestCase):
p.start() p.start()
time.sleep(10) time.sleep(10)
with open("/tmp/paddle.%d.selected_port" % p.pid, "r") as fn: with open("/tmp/paddle.%d.port" % p.pid, "r") as fn:
selected_port = int(fn.readlines()[0]) selected_port = int(fn.readlines()[0])
self.init_client(place, selected_port) self.init_client(place, selected_port)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册