Skip to content

Commit 3da0cb6

Browse files
committed
Optimize temporary file handling
1 parent f82ae64 commit 3da0cb6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cyaron/graders/testlib_checker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ def __init__(self, checker_path: str):
3030
self.checker_path = checker_path
3131

3232
def __call__(self, outs: str, ans: str, ins: str):
33-
with tempfile.NamedTemporaryFile('w') as inf, \
34-
tempfile.NamedTemporaryFile('w') as outf, \
35-
tempfile.NamedTemporaryFile('w') as ansf, \
36-
tempfile.TemporaryDirectory() as checker_output_dir:
33+
with tempfile.TemporaryDirectory() as checker_temp_dir, \
34+
open(path_join(checker_temp_dir, 'input.txt'), 'w', newline='\n') as inf, \
35+
open(path_join(checker_temp_dir, 'output.txt'), 'w', newline='\n') as outf, \
36+
open(path_join(checker_temp_dir, 'answer.txt'), 'w', newline='\n') as ansf:
3737
inf.write(ins)
3838
outf.write(outs)
3939
ansf.write(ans)
4040
inf.flush()
4141
outf.flush()
4242
ansf.flush()
43-
checker_output_file = path_join(checker_output_dir,
43+
checker_output_file = path_join(checker_temp_dir,
4444
'checker_output.xml')
4545

4646
result = subprocess.run((self.checker_path, inf.name, outf.name,

0 commit comments

Comments
 (0)