Spaces:
Runtime error
Runtime error
Muennighoff
commited on
Commit
•
4df2f12
1
Parent(s):
be2051a
Remove double timeouts
Browse files- execute.py +13 -19
execute.py
CHANGED
@@ -116,8 +116,7 @@ def unsafe_execute_cpp(check_program, result, timeout):
|
|
116 |
result.append(f"failed: compilation error: {err}")
|
117 |
else:
|
118 |
try:
|
119 |
-
|
120 |
-
exec_result = subprocess.run(["./a.out"], timeout=timeout, capture_output=True)
|
121 |
|
122 |
if exec_result.returncode == 0:
|
123 |
result.append("passed")
|
@@ -134,21 +133,21 @@ def unsafe_execute_cpp(check_program, result, timeout):
|
|
134 |
err = exec_result.stdout
|
135 |
result.append(f"failed: {err}")
|
136 |
|
137 |
-
except
|
138 |
result.append("timed out")
|
139 |
|
140 |
def unsafe_execute_java(check_program, result, timeout):
|
141 |
|
142 |
with create_tempdir():
|
143 |
-
|
144 |
open(f"Main.java", 'w').write(check_program)
|
145 |
|
146 |
res = "failed: unknown error"
|
147 |
compile_returncode = -1
|
148 |
for _ in range(5):
|
149 |
try:
|
150 |
-
compilation_result = subprocess.run(
|
151 |
-
|
|
|
152 |
compile_returncode = compilation_result.returncode
|
153 |
break
|
154 |
except subprocess.TimeoutExpired as e:
|
@@ -157,8 +156,7 @@ def unsafe_execute_java(check_program, result, timeout):
|
|
157 |
res = "failed: compilation error"
|
158 |
else:
|
159 |
try:
|
160 |
-
|
161 |
-
exec_result = subprocess.run([f'java', '-cp', tmp_dir, 'Main'], timeout=timeout, capture_output=True)
|
162 |
if exec_result.returncode == 0:
|
163 |
res = "passed"
|
164 |
elif exec_result.returncode == 1:
|
@@ -166,26 +164,22 @@ def unsafe_execute_java(check_program, result, timeout):
|
|
166 |
res = "failed: wrong answer"
|
167 |
else:
|
168 |
res = f"failed: {exec_result.stderr.decode()}"
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
result.append(res)
|
174 |
|
175 |
-
|
176 |
-
result.append("timed out")
|
177 |
|
178 |
def unsafe_execute_js(check_program, result, timeout):
|
179 |
|
180 |
with create_tempdir():
|
181 |
-
|
182 |
open(f"test.js", 'w').write(check_program)
|
183 |
|
184 |
# Run program.
|
185 |
try:
|
186 |
exec_globals = {}
|
187 |
-
|
188 |
-
exec_result = subprocess.run(["node", "test.js"], timeout=timeout, capture_output=True)
|
189 |
if exec_result.stderr.decode():
|
190 |
err = exec_result.stderr.decode()
|
191 |
result.append(f"failed: {err}")
|
@@ -195,7 +189,7 @@ def unsafe_execute_js(check_program, result, timeout):
|
|
195 |
else:
|
196 |
result.append("passed")
|
197 |
|
198 |
-
except
|
199 |
result.append("timed out")
|
200 |
|
201 |
|
|
|
116 |
result.append(f"failed: compilation error: {err}")
|
117 |
else:
|
118 |
try:
|
119 |
+
exec_result = subprocess.run(["./a.out"], timeout=timeout, capture_output=True)
|
|
|
120 |
|
121 |
if exec_result.returncode == 0:
|
122 |
result.append("passed")
|
|
|
133 |
err = exec_result.stdout
|
134 |
result.append(f"failed: {err}")
|
135 |
|
136 |
+
except subprocess.TimeoutExpired as e:
|
137 |
result.append("timed out")
|
138 |
|
139 |
def unsafe_execute_java(check_program, result, timeout):
|
140 |
|
141 |
with create_tempdir():
|
|
|
142 |
open(f"Main.java", 'w').write(check_program)
|
143 |
|
144 |
res = "failed: unknown error"
|
145 |
compile_returncode = -1
|
146 |
for _ in range(5):
|
147 |
try:
|
148 |
+
compilation_result = subprocess.run(
|
149 |
+
['javac', "Main.java"], timeout=5, capture_output=True
|
150 |
+
)
|
151 |
compile_returncode = compilation_result.returncode
|
152 |
break
|
153 |
except subprocess.TimeoutExpired as e:
|
|
|
156 |
res = "failed: compilation error"
|
157 |
else:
|
158 |
try:
|
159 |
+
exec_result = subprocess.run([f'java', '-cp', tmp_dir, 'Main'], timeout=timeout, capture_output=True)
|
|
|
160 |
if exec_result.returncode == 0:
|
161 |
res = "passed"
|
162 |
elif exec_result.returncode == 1:
|
|
|
164 |
res = "failed: wrong answer"
|
165 |
else:
|
166 |
res = f"failed: {exec_result.stderr.decode()}"
|
167 |
+
except subprocess.TimeoutExpired as e:
|
168 |
+
res = "timed out"
|
169 |
+
except BaseException as e:
|
170 |
+
res = f"failed: {e}"
|
|
|
171 |
|
172 |
+
result.append(res)
|
|
|
173 |
|
174 |
def unsafe_execute_js(check_program, result, timeout):
|
175 |
|
176 |
with create_tempdir():
|
|
|
177 |
open(f"test.js", 'w').write(check_program)
|
178 |
|
179 |
# Run program.
|
180 |
try:
|
181 |
exec_globals = {}
|
182 |
+
exec_result = subprocess.run(["node", "test.js"], timeout=timeout, capture_output=True)
|
|
|
183 |
if exec_result.stderr.decode():
|
184 |
err = exec_result.stderr.decode()
|
185 |
result.append(f"failed: {err}")
|
|
|
189 |
else:
|
190 |
result.append("passed")
|
191 |
|
192 |
+
except subprocess.TimeoutExpired as e:
|
193 |
result.append("timed out")
|
194 |
|
195 |
|