Merge pull request #10832 from typhoonzero/fix_server_port_file_conflict

fix dist test
shanyi15-patch-3
Yu Yang 7 years ago committed by GitHub
commit a9f9fbadd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
limitations under the License. */
#include <stdio.h> // for removing the port file
#include <fstream>
#include <ostream>
#include <thread> // NOLINT
@ -77,12 +78,14 @@ ListenAndServOp::ListenAndServOp(const std::string &type,
void ListenAndServOp::Stop() {
rpc_service_->Push(LISTEN_TERMINATE_MESSAGE);
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
selected_port_ = rpc_service_->GetSelectedPort();
auto file_path = string::Sprintf("/tmp/paddle.%d.port", ::getpid());
std::ofstream port_file;
port_file.open(file_path);
port_file << selected_port_.load();
@ -331,7 +334,7 @@ void ListenAndServOp::RunImpl(const framework::Scope &scope,
// Write to a file of server selected port for python use.
std::string file_path = string::Sprintf("/tmp/paddle.%d.selected_port",
static_cast<int>(::getpid()));
SavePort(file_path);
SavePort();
if (sync_mode) {
RunSyncLoop(&executor, program, &recv_scope, prefetch_block);
} else {

@ -48,8 +48,7 @@ class ListenAndServOp : public framework::OperatorBase {
void RunAsyncLoop(framework::Executor* executor,
framework::ProgramDesc* program) const;
void SavePort(
const std::string& file_path = "/tmp/paddle.selected_port") const;
void SavePort() const;
void WaitServerReady();

@ -34,7 +34,7 @@ class TestSendOp(unittest.TestCase):
p.start()
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])
self.init_client(place, selected_port)

Loading…
Cancel
Save