From 98924f4ac0a07cd9d4bb74322364347493e73159 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 8 Sep 2025 14:50:40 -0400 Subject: Improve reporting format, separate samples based on tident --- nemesis/nemesis.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'nemesis/nemesis.py') diff --git a/nemesis/nemesis.py b/nemesis/nemesis.py index 69d0c2b..c20d68d 100755 --- a/nemesis/nemesis.py +++ b/nemesis/nemesis.py @@ -25,7 +25,6 @@ Commentary: Code: ''' -from asyncio.base_events import _format_handle from collections import defaultdict from experiment import Experiment import argparse @@ -128,12 +127,21 @@ class Nemesis(object): def _get_waiting_handles(loop): handles = [] for handle in loop._ready: - if (fmt_handle := _format_handle(handle)) is not None \ - and fmt_handle not in handles: - # no duplicates - handles.append(fmt_handle) + # no duplicates + handle_info = Nemesis._parse_handle(handle) + if handle_info not in handles: + handles.append(handle_info) return handles + def _parse_handle(handle): + cb = handle._callback + if isinstance(getattr(cb, '__self__', None), asyncio.tasks.Task): + task = cb.__self__ + coro = task.get_coro() + return [task.get_name(), Nemesis.get_coro_name(coro)] + else: + return [str(type(handle).__name__), cb.__name__] + def _get_current_coro(loop): tid = loop._thread_id assert tid, f"{loop} is not running, yet we attempted to sample it!" @@ -173,6 +181,22 @@ class Nemesis(object): return False return True + def get_coro_name(coro): + ''' + Stolen from _format_coroutine in cpython/Lib/asyncio/coroutines.py + ''' + # Coroutines compiled with Cython sometimes don't have + # proper __qualname__ or __name__. While that is a bug + # in Cython, asyncio shouldn't crash with an AttributeError + # in its __repr__ functions. + if hasattr(coro, '__qualname__') and coro.__qualname__: + coro_name = coro.__qualname__ + elif hasattr(coro, '__name__') and coro.__name__: + coro_name = coro.__name__ + else: + # Stop masking Cython bugs, expose them in a friendly way. + coro_name = f'<{type(coro).__name__} without __name__>' + return f'{coro_name}()' the_globals = { '__name__': '__main__', -- cgit v1.2.3