Skip to content

Commit 004aa01

Browse files
committed
Set timeout for the dependency analysis of Python files
It's too slow for Python scripts which depends large libraries. This partially resolves #308
1 parent 30b57ff commit 004aa01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

onlinejudge_verify/languages/python.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Python Version: 3.x
2+
import concurrent.futures
23
import functools
34
import pathlib
45
import sys
@@ -53,7 +54,12 @@ def _python_list_depending_files(path: pathlib.Path, basedir: pathlib.Path) -> L
5354
importlab.fs.Path([importlab.fs.OSFileSystem(str(basedir.resolve()))]),
5455
(sys.version_info.major, sys.version_info.minor),
5556
)
56-
res_graph = importlab.graph.ImportGraph.create(env, [str(path)])
57+
try:
58+
executor = concurrent.futures.ThreadPoolExecutor()
59+
future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)])
60+
res_graph = future.result(timeout=1.0)
61+
except concurrent.futures.TimeoutError as e:
62+
raise RuntimeError(f"Failed to analyze the dependency graph (timeout): {path}") from e
5763
try:
5864
node_deps_pairs = res_graph.deps_list() # type: List[Tuple[str, List[str]]]
5965
except Exception as e:

0 commit comments

Comments
 (0)