Skip to content

Commit 5fe8de9

Browse files
author
yi.wu
committed
fix dist test
1 parent dac0679 commit 5fe8de9

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

paddle/fluid/operators/listen_and_serv_op.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15+
#include <stdio.h> // for removing the port file
1516
#include <fstream>
1617
#include <ostream>
1718
#include <thread> // NOLINT
@@ -77,12 +78,14 @@ ListenAndServOp::ListenAndServOp(const std::string &type,
7778
void ListenAndServOp::Stop() {
7879
rpc_service_->Push(LISTEN_TERMINATE_MESSAGE);
7980
server_thread_->join();
81+
auto file_path = string::Sprintf("/tmp/paddle.%d.port", ::getpid());
82+
remove(file_path.c_str());
8083
}
8184

82-
void ListenAndServOp::SavePort(const std::string &file_path) const {
85+
void ListenAndServOp::SavePort() const {
8386
// NOTE: default write file to /tmp/paddle.selected_port
8487
selected_port_ = rpc_service_->GetSelectedPort();
85-
88+
auto file_path = string::Sprintf("/tmp/paddle.%d.port", ::getpid());
8689
std::ofstream port_file;
8790
port_file.open(file_path);
8891
port_file << selected_port_.load();
@@ -331,7 +334,7 @@ void ListenAndServOp::RunImpl(const framework::Scope &scope,
331334
// Write to a file of server selected port for python use.
332335
std::string file_path = string::Sprintf("/tmp/paddle.%d.selected_port",
333336
static_cast<int>(::getpid()));
334-
SavePort(file_path);
337+
SavePort();
335338
if (sync_mode) {
336339
RunSyncLoop(&executor, program, &recv_scope, prefetch_block);
337340
} else {

paddle/fluid/operators/listen_and_serv_op.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ class ListenAndServOp : public framework::OperatorBase {
4848
void RunAsyncLoop(framework::Executor* executor,
4949
framework::ProgramDesc* program) const;
5050

51-
void SavePort(
52-
const std::string& file_path = "/tmp/paddle.selected_port") const;
51+
void SavePort() const;
5352

5453
void WaitServerReady();
5554

python/paddle/fluid/tests/unittests/test_dist_train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_send(self):
3434
p.start()
3535

3636
time.sleep(10)
37-
with open("/tmp/paddle.%d.selected_port" % p.pid, "r") as fn:
37+
with open("/tmp/paddle.%d.port" % p.pid, "r") as fn:
3838
selected_port = int(fn.readlines()[0])
3939
self.init_client(place, selected_port)
4040

0 commit comments

Comments
 (0)