MCPcopy Create free account
hub / github.com/InternLM/InternBootcamp / call_with_timeout

Function call_with_timeout

internbootcamp/utils/data_generation.py:30–57  ·  view source on GitHub ↗

带超时的函数调用 Args: func: 要调用的函数 timeout_seconds: 超时时间(秒) Returns: 函数的返回值 Raises: TimeoutException: 如果函数执行超时

(func, timeout_seconds=60)

Source from the content-addressed store, hash-verified

28
29
30def call_with_timeout(func, timeout_seconds=60):
31 """
32 带超时的函数调用
33
34 Args:
35 func: 要调用的函数
36 timeout_seconds: 超时时间(秒)
37
38 Returns:
39 函数的返回值
40
41 Raises:
42 TimeoutException: 如果函数执行超时
43 """
44 # 设置信号处理器
45 signal.signal(signal.SIGALRM, timeout_handler)
46 signal.alarm(timeout_seconds)
47
48 try:
49 result = func()
50 signal.alarm(0) # 取消alarm
51 return result
52 except TimeoutException:
53 signal.alarm(0) # 取消alarm
54 raise
55 except Exception as e:
56 signal.alarm(0) # 取消alarm
57 raise e
58
59def load_instruction_generators_from_config(config_path: str) -> List[Dict[str, Any]]:
60 """

Callers

nothing calls this directly

Calls 1

funcFunction · 0.85

Tested by

no test coverage detected