Skip to content

Commit 9d96e2c

Browse files
committed
Use an ephemeral port in bm_asyncio_tcp
1 parent 8a0713c commit 9d96e2c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎pyperformance/data-files/benchmarks/bm_asyncio_tcp/run_benchmark.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ async def main(use_ssl: bool) -> None:
4242
server_context = None
4343
client_context = None
4444

45-
server = await asyncio.start_server(handle_echo, '127.0.0.1', 8882, ssl=server_context)
45+
# Bind to an ephemeral port (port 0) and read back the port the kernel
46+
# assigned. This keeps concurrent runs (e.g. asyncio_tcp and
47+
# asyncio_tcp_ssl running in parallel) from colliding on a fixed port.
48+
server = await asyncio.start_server(handle_echo, '127.0.0.1', 0, ssl=server_context)
49+
host, port = server.sockets[0].getsockname()[:2]
4650

4751
async with server:
4852
asyncio.create_task(server.start_serving())
49-
reader, writer = await asyncio.open_connection('127.0.0.1', 8882, ssl=client_context)
53+
reader, writer = await asyncio.open_connection(host, port, ssl=client_context)
5054
data_len = 0
5155
while True:
5256
data = await reader.read(CHUNK_SIZE)

0 commit comments

Comments
 (0)