From cb884725cd530428aa7871d7eb0ac6fbc426122f Mon Sep 17 00:00:00 2001 From: Sendao Yan Date: Thu, 19 Nov 2026 11:13:41 +0800 Subject: [PATCH] Use an ephemeral port in bm_asyncio_websockets --- .../benchmarks/bm_asyncio_websockets/run_benchmark.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyperformance/data-files/benchmarks/bm_asyncio_websockets/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_asyncio_websockets/run_benchmark.py index 12d2df45..1eb453f9 100644 --- a/pyperformance/data-files/benchmarks/bm_asyncio_websockets/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_asyncio_websockets/run_benchmark.py @@ -35,8 +35,9 @@ async def main() -> None: global stop t0 = pyperf.perf_counter() stop = asyncio.Event() - async with websockets.server.serve(handler, "", 8001): - async with websockets.client.connect("ws://localhost:8001") as ws: + async with websockets.server.serve(handler, "127.0.0.1", 0) as server: + port = server.sockets[0].getsockname()[1] + async with websockets.client.connect(f"ws://127.0.0.1:{port}") as ws: await asyncio.gather(*[send(ws) for _ in range(100)]) await stop.wait() return pyperf.perf_counter() - t0