Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a36f907

Browse files
committed
Implement Time Limit Exceeded error for slow solutions
1 parent 1d26435 commit a36f907

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

‎src/app/testrunner.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import logger
1010
import resultsdiffer
1111

12+
# In the future this might depend on the language (e.g. for pyhon, use 15s)
13+
PROBLEM_LTE_S = 3
14+
1215
def sort_key(file):
1316
# Extract the number from the filename
1417
match = re.search(r'\d+', file)
@@ -60,13 +63,20 @@ def runTest(exec_filename, testcase_filename, output_filename):
6063
return 1, f"The file {testcase_filename} does not exist."
6164

6265
try:
63-
result = subprocess.run([os.path.basename(exec_filename),
64-
os.path.abspath(testcase_filename),
65-
os.path.abspath(output_filename)],
66-
shell=True,
66+
command = (
67+
f"{os.path.abspath(exec_filename)} "
68+
f"{os.path.abspath(testcase_filename)} "
69+
f"{os.path.abspath(output_filename)}"
70+
)
71+
logger.log(f"Running command: {command}")
72+
result = subprocess.run(command,
73+
shell=False,
6774
cwd=os.path.dirname(exec_filename),
75+
timeout=PROBLEM_LTE_S,
6876
stderr=subprocess.PIPE)
77+
except subprocess.TimeoutExpired:
78+
return 1, f"Time Limit Exceeded"
6979
except Exception as e:
70-
return 1, f"Error running the test{e}"
80+
return 1, f"Error running the test, command={command}, error={e}"
7181

7282
return result.returncode, result.stderr.decode()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /