Skip to content

Commit fc08cd5

Browse files
authored
Merge pull request #356 from online-judge-tools/fix/timeout-for-python
Set timeout for the dependency analysis of Python files
2 parents 3fb0b1c + 4b686f8 commit fc08cd5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

onlinejudge_verify/languages/python.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Python Version: 3.x
2+
import concurrent.futures
23
import functools
34
import pathlib
5+
import platform
46
import sys
57
import textwrap
68
from logging import getLogger
@@ -53,7 +55,16 @@ def _python_list_depending_files(path: pathlib.Path, basedir: pathlib.Path) -> L
5355
importlab.fs.Path([importlab.fs.OSFileSystem(str(basedir.resolve()))]),
5456
(sys.version_info.major, sys.version_info.minor),
5557
)
56-
res_graph = importlab.graph.ImportGraph.create(env, [str(path)])
58+
try:
59+
executor = concurrent.futures.ThreadPoolExecutor()
60+
future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)])
61+
if platform.uname().system == 'Windows':
62+
timeout = 5.0 # 1.0 sec causes timeout on CI using Windows
63+
else:
64+
timeout = 1.0
65+
res_graph = future.result(timeout=timeout)
66+
except concurrent.futures.TimeoutError as e:
67+
raise RuntimeError(f"Failed to analyze the dependency graph (timeout): {path}") from e
5768
try:
5869
node_deps_pairs = res_graph.deps_list() # type: List[Tuple[str, List[str]]]
5970
except Exception as e:

0 commit comments

Comments
 (0)