|  |  | @ -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, | 
			
		
	
		
		
			
				
					
					|  |  |  | 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, | 
			
		
	
		
		
			
				
					
					|  |  |  |   // 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 { | 
			
		
	
	
		
		
			
				
					|  |  | 
 |