(
lock: BaseFileLock, callee: CodeType | None, on_call: Callable[[], object]
)
| 68 | |
| 69 | |
| 70 | def _interrupt_hook( |
| 71 | lock: BaseFileLock, callee: CodeType | None, on_call: Callable[[], object] |
| 72 | ) -> Callable[[FrameType, str, Unused], None]: |
| 73 | # Interpreters run a profile hook with tracing off, so coverage never records its body. |
| 74 | # Where the hook would end a resumed generator without its finally, only a fresh call models a signal. |
| 75 | resumable: Final[bool] = CAPABILITIES["profile-interrupted-generator-finishes"] |
| 76 | entered: Final[set[FrameType]] = set() |
| 77 | |
| 78 | def hook(frame: FrameType, event: str, _arg: Unused) -> None: # pragma: no cover # runs inside the profile hook |
| 79 | # Injecting signals inside threading's own context managers can leak their locks. |
| 80 | if event != "call" or (callee is not None and frame.f_code is not callee): |
| 81 | return |
| 82 | holder = frame if callee is None else frame.f_back |
| 83 | if ( |
| 84 | (resumable or frame not in entered) |
| 85 | and holder is not None |
| 86 | and any(v is lock for v in holder.f_locals.values()) |
| 87 | ): |
| 88 | entered.add(frame) |
| 89 | on_call() |
| 90 | |
| 91 | return hook |
| 92 | |
| 93 | |
| 94 | def _interrupted_at_call( |
no outgoing calls
no test coverage detected