diff options
| author | bd <bdunahu@operationnull.com> | 2025-07-01 15:57:17 -0400 |
|---|---|---|
| committer | bd <bdunahu@operationnull.com> | 2025-07-01 15:57:17 -0400 |
| commit | e0b5a46e51f1da0125bbdb67b23591c20aeee070 (patch) | |
| tree | c664960299a255aaea67ab69947031d9a44929c6 /aergia | |
| parent | 708b2fc12bc6016c7359ea603c115950bddfefc5 (diff) | |
Search for AbstractEventLoop object rather than Runner
This has a better chance of working with other platforms, and also catches event loops created manually (flask)
Diffstat (limited to 'aergia')
| -rwxr-xr-x | aergia | 41 |
1 files changed, 23 insertions, 18 deletions
@@ -181,7 +181,7 @@ class Aergia(object): @staticmethod def compute_frames_to_record(): '''Collects all stack frames that Aergia actually processes.''' - frames = Aergia.get_frames_from_runners(Aergia.get_event_loops()) + frames = Aergia.get_frames_from_loops(Aergia.get_event_loops()) # Process all the frames to remove ones we aren't going to track. new_frames = [] @@ -212,41 +212,45 @@ class Aergia(object): @staticmethod def get_event_loops(): - runners = [] + loops = [] for t in threading.enumerate(): frame = sys._current_frames().get(t.ident) if not frame: continue - runner = Aergia.walk_back_until_runner(frame) - if runner: - runners.append(runner) - return runners + # print(f'searching frame {frame}') + loop = Aergia.walk_back_until_loop(frame) + if loop: + # print(f'found loop {loop}') + loops.append(loop) + return loops @staticmethod - def walk_back_until_runner(frame): + def walk_back_until_loop(frame): while frame: - r = Aergia.find_runner_in_locals(frame.f_locals) - if r: - return r + loop = Aergia.find_loop_in_locals(frame.f_locals) + if loop: + return loop frame = frame.f_back return None @staticmethod - def find_runner_in_locals(locals_dict): + def find_loop_in_locals(locals_dict): '''Given a dictionary of local variables for a stack frame, - retrieves the asyncio runner object, if there is one.''' + retrieves the asyncio loop object, if there is one. + + This function should work on Windows, but this is dubious because + I don't have a system to test with.''' for val in locals_dict.values(): - if type(val).__name__ == 'Runner' and \ - val.__class__.__module__ == 'asyncio.runners': + if isinstance(val, asyncio.AbstractEventLoop): return val return None @staticmethod - def get_frames_from_runners(runners): - '''Given RUNNERS, returns a flat list of tasks.''' + def get_frames_from_loops(loops): + '''Given LOOPS, returns a flat list of tasks.''' return [ - task for runner in runners - for task in Aergia.get_idle_task_frames(runner._loop) + task for loop in loops + for task in Aergia.get_idle_task_frames(loop) ] @staticmethod @@ -262,6 +266,7 @@ class Aergia(object): @staticmethod def should_trace(filename): '''Returns FALSE if filename is uninteresting to the user.''' + # return True # FIXME Assume GuixSD. Makes filtering easy if '/gnu/store' in filename: return False |
