GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — profiling.sampling: exception mode misses except blocks running in generators and coroutines · Issue #158539 · python/cpython Closed Labels interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportBackgroundI have been writing a set of guided workshops on Tachyon as a way of learning it (https://github.com/GrahamDumpleton/tachyon-workshops), using an AI agent to generate the workshop content. While working on a workshop about exception mode, the agent found that a function which catches exceptions had far fewer samples in That seems reasonable to me, but I do not have the knowledge of the internals to say whether this is a bug, a known shortcoming, or by design, so I am reporting what was found and how to reproduce it. The analysis of the cause at the end is the agent's, and I cannot evaluate it myself. What the documentation saysThe exception mode section of the What happensAn The script below has five cases. Each raises import asyncio import time def busy(seconds): end = time.perf_counter() + seconds while time.perf_counter() < end: pass def handler_in_function(): try: raise ValueError("handled in a function") except ValueError: busy(1.0) def handler_in_generator(): try: raise ValueError("handled in a generator") except ValueError: busy(1.0) yield def handler_in_genexpr_callee(): try: raise ValueError("handled in a function called from a generator expression") except ValueError: busy(1.0) async def handler_in_coroutine(): try: raise ValueError("handled in a coroutine") except ValueError: busy(1.0) async def calls_handler_from_coroutine(): handler_in_coroutine_callee() def handler_in_coroutine_callee(): try: raise ValueError("handled in a function called from a coroutine") except ValueError: busy(1.0) handler_in_function() for _ in handler_in_generator(): pass list(handler_in_genexpr_callee() for _ in range(1)) asyncio.run(handler_in_coroutine()) asyncio.run(calls_handler_from_coroutine()) Run it in wall-clock mode and then in exception mode: Wall-clock mode sees all five handlers for about a second each (rows for Exception mode sees only the first:
The exception mode run reports an error rate of 0.00 and captured over 5000 samples, so the samples were taken; they were then discarded by the mode's filter. From inside the program, This was reproduced on two builds of 3.15.0rc2, the If the behaviour is intended, the practical effect seems worth noting in the docs: in an asyncio program every AI analysis of the cause (not verified by me)What follows is the agent's reading of the source. I am including it in case it saves someone time, but I cannot judge whether it is right. In // Check exc_state.exc_value (exception being handled in except block) // exc_state is embedded in PyThreadState, so we read it directly from // the thread state buffer. This catches most cases; nested exception // handlers where exc_info points elsewhere are rare. if (!has_exception) { uintptr_t exc_value = GET_MEMBER(uintptr_t, ts, unwinder->debug_offsets.thread_state.exc_state + unwinder->debug_offsets.err_stackitem.exc_value); if (exc_value != 0) { has_exception = 1; } } The agent's explanation is that the interpreter records a handled exception in It also noted that PR #142561, which added the mode, describes the check as using The suggested fix was to add CPython versions tested on:3.15 Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||||||||||||
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |