MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / with_timeout

Function with_timeout

benchmarks/src/utils/timing.py:30–42  ·  view source on GitHub ↗
(fn: Callable[..., T], timeout_s: float)

Source from the content-addressed store, hash-verified

28
29
30def with_timeout(fn: Callable[..., T], timeout_s: float) -> T:
31 global TIMEOUT_POOL
32
33 if TIMEOUT_POOL is None:
34 # it needs to be more than 1 to avoid deadlocks when with_timeout is nested
35 TIMEOUT_POOL = ThreadPool(8)
36 atexit.register(TIMEOUT_POOL.close)
37
38 future = TIMEOUT_POOL.apply_async(fn)
39 try:
40 return future.get(timeout=timeout_s)
41 except multiprocessing.context.TimeoutError:
42 raise TimeoutException()
43
44
45class Timings:

Callers 3

executeFunction · 0.90
execute_benchmarkFunction · 0.85

Calls 3

registerMethod · 0.80
TimeoutExceptionClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected