| 31 | |
| 32 | # NOTE: @C-Achard 2026-03-10 deprecated, as this is not used for the update check anymore |
| 33 | def 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.") |