@@ -54,38 +54,38 @@ def gloo_init_parallel_env(
5454 None
5555
5656 Examples:
57- .. code-block:: python
57+ .. code-block:: pycon
5858
5959 >>> import paddle
6060 >>> import multiprocessing
6161 >>> from contextlib import closing
6262 >>> import socket
6363
64- >>> port_set = set() # type: ignore
64+ >>> port_set = set() # type: ignore
6565
6666 >>> def find_free_port():
6767 ... def _free_port():
68- ... with closing(socket.socket(socket.AF_INET,
69- ... socket.SOCK_STREAM)) as s:
68+ ... with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
7069 ... s.bind(('', 0))
7170 ... return s.getsockname()[1]
71+ ...
7272 ... while True:
7373 ... port = _free_port()
7474 ... if port not in port_set:
7575 ... port_set.add(port)
7676 ... return port
7777
7878 >>> def test_gloo_init(id, rank_num, server_endpoint):
79- ... paddle.distributed.gloo_init_parallel_env(
80- ... id, rank_num, server_endpoint)
79+ ... paddle.distributed.gloo_init_parallel_env(id, rank_num, server_endpoint)
8180
8281 >>> def test_gloo_init_with_multiprocess(num_of_ranks):
8382 ... jobs = []
8483 ... server_endpoint = "127.0.0.1:%s" % (find_free_port())
8584 ... for id in range(num_of_ranks):
8685 ... p = multiprocessing.Process(
8786 ... target=test_gloo_init,
88- ... args=(id, num_of_ranks, server_endpoint))
87+ ... args=(id, num_of_ranks, server_endpoint),
88+ ... )
8989 ... jobs.append(p)
9090 ... p.start()
9191 ... for proc in jobs:
@@ -149,30 +149,29 @@ def gloo_barrier() -> None:
149149 None
150150
151151 Examples:
152- .. code-block:: python
152+ .. code-block:: pycon
153153
154154 >>> import paddle
155155 >>> import multiprocessing
156156 >>> from contextlib import closing
157157 >>> import socket
158158
159- >>> port_set = set() # type: ignore
159+ >>> port_set = set() # type: ignore
160160
161161 >>> def find_free_port():
162162 ... def _free_port():
163- ... with closing(socket.socket(socket.AF_INET,
164- ... socket.SOCK_STREAM)) as s:
163+ ... with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
165164 ... s.bind(('', 0))
166165 ... return s.getsockname()[1]
166+ ...
167167 ... while True:
168168 ... port = _free_port()
169169 ... if port not in port_set:
170170 ... port_set.add(port)
171171 ... return port
172172
173173 >>> def test_gloo_barrier(id, rank_num, server_endpoint):
174- ... paddle.distributed.gloo_init_parallel_env(
175- ... id, rank_num, server_endpoint)
174+ ... paddle.distributed.gloo_init_parallel_env(id, rank_num, server_endpoint)
176175 ... paddle.distributed.gloo_barrier()
177176
178177 >>> def test_gloo_barrier_with_multiprocess(num_of_ranks):
@@ -181,7 +180,8 @@ def gloo_barrier() -> None:
181180 ... for id in range(num_of_ranks):
182181 ... p = multiprocessing.Process(
183182 ... target=test_gloo_barrier,
184- ... args=(id, num_of_ranks, server_endpoint))
183+ ... args=(id, num_of_ranks, server_endpoint),
184+ ... )
185185 ... jobs.append(p)
186186 ... p.start()
187187 ... for proc in jobs:
@@ -207,30 +207,29 @@ def gloo_release() -> None:
207207 None
208208
209209 Examples:
210- .. code-block:: python
210+ .. code-block:: pycon
211211
212212 >>> import paddle
213213 >>> import multiprocessing
214214 >>> from contextlib import closing
215215 >>> import socket
216216
217- >>> port_set = set() # type: ignore
217+ >>> port_set = set() # type: ignore
218218
219219 >>> def find_free_port():
220220 ... def _free_port():
221- ... with closing(socket.socket(socket.AF_INET,
222- ... socket.SOCK_STREAM)) as s:
221+ ... with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
223222 ... s.bind(('', 0))
224223 ... return s.getsockname()[1]
224+ ...
225225 ... while True:
226226 ... port = _free_port()
227227 ... if port not in port_set:
228228 ... port_set.add(port)
229229 ... return port
230230
231231 >>> def test_gloo_release(id, rank_num, server_endpoint):
232- ... paddle.distributed.gloo_init_parallel_env(
233- ... id, rank_num, server_endpoint)
232+ ... paddle.distributed.gloo_init_parallel_env(id, rank_num, server_endpoint)
234233 ... paddle.distributed.gloo_barrier()
235234 ... paddle.distributed.gloo_release()
236235
@@ -240,7 +239,8 @@ def gloo_release() -> None:
240239 ... for id in range(num_of_ranks):
241240 ... p = multiprocessing.Process(
242241 ... target=test_gloo_release,
243- ... args=(id, num_of_ranks, server_endpoint))
242+ ... args=(id, num_of_ranks, server_endpoint),
243+ ... )
244244 ... jobs.append(p)
245245 ... p.start()
246246 ... for proc in jobs:
0 commit comments