Skip to content

Commit 4af8712

Browse files
rchaotensorflower-gardener
authored andcommitted
Internal refactoring.
PiperOrigin-RevId: 235271388
1 parent 135fee1 commit 4af8712

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tensorflow/contrib/distribute/python/multi_worker_test_base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@
3737
from tensorflow.core.protobuf import config_pb2
3838
from tensorflow.core.protobuf import rewriter_config_pb2
3939
from tensorflow.python.client import session
40+
from tensorflow.python.distribute import distribute_coordinator as dc
4041
from tensorflow.python.estimator import run_config
4142
from tensorflow.python.platform import test
4243
from tensorflow.python.platform import tf_logging as logging
4344
from tensorflow.python.training import coordinator
4445
from tensorflow.python.training import server_lib
4546

47+
48+
original_run_std_server = dc._run_std_server # pylint: disable=protected-access
49+
4650
ASSIGNED_PORTS = set()
4751
lock = threading.Lock()
4852

@@ -357,6 +361,22 @@ def __len__(self):
357361
class IndependentWorkerTestBase(test.TestCase):
358362
"""Testing infra for independent workers."""
359363

364+
def _make_mock_run_std_server(self):
365+
thread_local = threading.local()
366+
367+
def _mock_run_std_server(*args, **kwargs):
368+
ret = original_run_std_server(*args, **kwargs)
369+
# Wait for all std servers to be brought up in order to reduce the chance
370+
# of remote sessions taking local ports that have been assigned to std
371+
# servers. Only call this barrier the first time this function is run for
372+
# each thread.
373+
if not getattr(thread_local, 'server_started', False):
374+
self._barrier.wait()
375+
thread_local.server_started = True
376+
return ret
377+
378+
return _mock_run_std_server
379+
360380
def setUp(self):
361381
self._mock_os_env = MockOsEnv()
362382
self._mock_context = test.mock.patch.object(os, 'environ',

0 commit comments

Comments
 (0)