MCPcopy Index your code
hub / github.com/DeepLabCut/DeepLabCut / call_with_timeout

Function call_with_timeout

deeplabcut/utils/multiprocessing.py:33–50  ·  view source on GitHub ↗
(func, timeout, *args, **kwargs)

Source from the content-addressed store, hash-verified

31
32# NOTE: @C-Achard 2026-03-10 deprecated, as this is not used for the update check anymore
33def call_with_timeout(func, timeout, *args, **kwargs):
34 queue = multiprocessing.Queue()
35 process = multiprocessing.Process(target=_wrapper, args=(func, queue, *args), kwargs=kwargs)
36 process.start()
37 process.join(timeout)
38
39 if process.is_alive():
40 process.terminate() # Forcefully terminate the process
41 process.join()
42 raise TimeoutError(f"Function {func.__name__} did not complete within {timeout} seconds.")
43
44 if not queue.empty():
45 result = queue.get()
46 if isinstance(result, Exception):
47 raise result # Re-raise the exception if it occurred in the function
48 return result
49 else:
50 raise TimeoutError(f"Function {func.__name__} completed but did not return a result.")

Callers 1

test_call_with_timeoutFunction · 0.90

Calls 4

startMethod · 0.80
emptyMethod · 0.80
terminateMethod · 0.45
getMethod · 0.45

Tested by 1

test_call_with_timeoutFunction · 0.72