MCPcopy Create free account
hub / github.com/tox-dev/filelock / _interrupt_hook

Function _interrupt_hook

tests/core/test_interruption.py:70–91  ·  view source on GitHub ↗
(
    lock: BaseFileLock, callee: CodeType | None, on_call: Callable[[], object]
)

Source from the content-addressed store, hash-verified

68
69
70def _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
94def _interrupted_at_call(

Callers 2

_interrupt_pointsFunction · 0.85
_interrupted_at_callFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected