@@ -55,6 +55,7 @@ def run_pserver(self, args):
55
55
pserver_prog = t .get_pserver_program (args .current_endpoint )
56
56
startup_prog = t .get_startup_program (args .current_endpoint ,
57
57
pserver_prog )
58
+
58
59
place = fluid .CPUPlace ()
59
60
exe = fluid .Executor (place )
60
61
exe .run (startup_prog )
@@ -147,6 +148,8 @@ def runtime_main(test_class):
147
148
148
149
149
150
import paddle .compat as cpt
151
+ import socket
152
+ from contextlib import closing
150
153
151
154
152
155
class TestDistBase (unittest .TestCase ):
@@ -156,13 +159,19 @@ def _setup_config(self):
156
159
def setUp (self ):
157
160
self ._trainers = 2
158
161
self ._pservers = 2
159
- self ._ps_endpoints = "127.0.0.1:9123,127.0.0.1:9124"
162
+ self ._ps_endpoints = "127.0.0.1:%s,127.0.0.1:%s" % (
163
+ self ._find_free_port (), self ._find_free_port ())
160
164
self ._python_interp = "python"
161
165
self ._sync_mode = True
162
166
self ._mem_opt = False
163
167
self ._use_reduce = False
164
168
self ._setup_config ()
165
169
170
+ def _find_free_port (self ):
171
+ with closing (socket .socket (socket .AF_INET , socket .SOCK_STREAM )) as s :
172
+ s .bind (('' , 0 ))
173
+ return s .getsockname ()[1 ]
174
+
166
175
def start_pserver (self , model_file , check_error_log ):
167
176
ps0_ep , ps1_ep = self ._ps_endpoints .split ("," )
168
177
ps_cmd = "%s %s --role pserver --endpoints %s --trainer_id 0 --current_endpoint %s --trainers %d --is_dist"
0 commit comments