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

Function _timeout_cpu

tasks/benchmark.py:81–94  ·  view source on GitHub ↗
(root: Path)

Source from the content-addressed store, hash-verified

79
80
81def _timeout_cpu(root: Path) -> Sample:
82 # A contended acquire with a zero poll interval should spin on the clock, not the CPU. Hold the lock, time out a
83 # second acquirer, and report the CPU time the wait burned; a busy loop would show wall-sized CPU here.
84 holder = FileLock(str(root / "timeout.lock"))
85 holder.acquire()
86 waiter = FileLock(str(root / "timeout.lock"))
87 try:
88 started = time.process_time()
89 with suppress(filelock.Timeout):
90 waiter.acquire(timeout=0.25, poll_interval=0.0)
91 cpu = time.process_time() - started
92 finally:
93 holder.release()
94 return Sample(name="timeout cpu (0.25s wall, poll=0)", median=cpu * 1e3, p95=cpu * 1e3, unit="ms cpu")
95
96
97def _descriptor_growth(root: Path) -> Sample:

Callers 1

mainFunction · 0.85

Calls 3

SampleClass · 0.85
acquireMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected