MCPcopy Index your code
hub / github.com/python/cpython / _get_stack_trace_with_retry

Function _get_stack_trace_with_retry

Lib/test/test_external_inspection.py:257–279  ·  view source on GitHub ↗

Get stack trace from an existing unwinder with retry for transient errors. This handles the case where we want to reuse an existing RemoteUnwinder instance but still handle transient failures like "Failed to parse initial frame in chain" that can occur when sampling at an inopportune mo

(unwinder, timeout=SHORT_TIMEOUT, condition=None)

Source from the content-addressed store, hash-verified

255
256
257def _get_stack_trace_with_retry(unwinder, timeout=SHORT_TIMEOUT, condition=None):
258 """Get stack trace from an existing unwinder with retry for transient errors.
259
260 This handles the case where we want to reuse an existing RemoteUnwinder
261 instance but still handle transient failures like "Failed to parse initial
262 frame in chain" that can occur when sampling at an inopportune moment.
263 If condition is provided, keeps retrying until condition(traces) is True.
264 """
265 last_error = None
266 for _ in busy_retry(timeout):
267 try:
268 traces = unwinder.get_stack_trace()
269 if condition is None or condition(traces):
270 return traces
271 # Condition not met yet, keep retrying
272 except TRANSIENT_ERRORS as e:
273 last_error = e
274 continue
275 if last_error:
276 raise RuntimeError(
277 f"Failed to get stack trace after retries: {last_error}"
278 )
279 raise RuntimeError("Condition never satisfied within timeout")
280
281
282# ============================================================================

Callers 2

test_get_statsMethod · 0.85

Calls 2

busy_retryFunction · 0.90
get_stack_traceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…