From 03d54b900cda3c179033ac16035b1c36ddcbd2de Mon Sep 17 00:00:00 2001 From: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:56:22 +0300 Subject: [PATCH] Refactor `collect_path_diversity` to run probes concurrently using `asyncio.gather`. (#25) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- src/netsleuth/probes/bgp_path.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/netsleuth/probes/bgp_path.py b/src/netsleuth/probes/bgp_path.py index 3a50e42..51c68a0 100644 --- a/src/netsleuth/probes/bgp_path.py +++ b/src/netsleuth/probes/bgp_path.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import re import httpx @@ -158,8 +159,9 @@ async def collect_path_diversity( timeout: float, source_ip: str | None = None, ) -> PathDiversity: - hops = [ - await probe_edge(client, host, timeout=timeout, source_ip=source_ip) + coros = [ + probe_edge(client, host, timeout=timeout, source_ip=source_ip) for _label, host in targets[:max_targets] ] - return build_path_diversity(client_country, hops) + hops = await asyncio.gather(*coros) + return build_path_diversity(client_country, list(hops))