Skip to content

Commit eeee45f

Browse files
authored
add timeout for changelog (Azure#39216)
1 parent 65c63f6 commit eeee45f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

tools/azure-sdk-tools/packaging_tools/sdk_package.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import os
66
from pathlib import Path
77
from subprocess import check_call
8+
from typing import Any
9+
import multiprocessing
10+
from functools import partial
811

912
from .package_utils import create_package, change_log_generate, extract_breaking_change
1013

@@ -16,6 +19,11 @@
1619
_LOGGER = logging.getLogger(__name__)
1720

1821

22+
def execute_func_with_timeout(func, timeout: int = 900) -> Any:
23+
"""Execute function with timeout"""
24+
return multiprocessing.Pool(processes=1).apply_async(func).get(timeout)
25+
26+
1927
def main(generate_input, generate_output):
2028
with open(generate_input, "r") as reader:
2129
data = json.load(reader)
@@ -28,14 +36,18 @@ def main(generate_input, generate_output):
2836
prefolder = package["path"][0]
2937
# Changelog
3038
last_version = ["first release"]
39+
change_log_func = partial(
40+
change_log_generate,
41+
package_name,
42+
last_version,
43+
package["tagIsStable"],
44+
prefolder=prefolder,
45+
is_multiapi=package["isMultiapi"],
46+
)
3147
try:
32-
md_output = change_log_generate(
33-
package_name,
34-
last_version,
35-
package["tagIsStable"],
36-
prefolder=prefolder,
37-
is_multiapi=package["isMultiapi"],
38-
)
48+
md_output = execute_func_with_timeout(change_log_func)
49+
except multiprocessing.TimeoutError:
50+
md_output = "change log generation was timeout!!!"
3951
except:
4052
md_output = "change log generation failed!!!"
4153
package["changelog"] = {

0 commit comments

Comments
 (0)