@@ -403,16 +403,18 @@ def check_output(self, name, input_file, output_file_path, output, answer_file_p
403
403
output_file .write ("\n " .join (output ) + "\n " )
404
404
return self .check_output_checker (name , input_file , output_file_path , answer_file_path )
405
405
406
- def execute_oiejq (self , command , name , result_file_path , input_file_path , output_file_path , answer_file_path ,
406
+ def execute_oiejq (self , name , timetool_path , executable , result_file_path , input_file_path , output_file_path , answer_file_path ,
407
407
time_limit , memory_limit , hard_time_limit ):
408
+ command = f'"{ timetool_path } " "{ executable } "'
408
409
env = os .environ .copy ()
409
410
env ["MEM_LIMIT" ] = f'{ memory_limit } K'
410
411
env ["MEASURE_MEM" ] = "1"
411
412
412
413
timeout = False
413
- with open (input_file_path , "r" ) as input_file :
414
- process = subprocess .Popen (command , shell = True , stdin = input_file , stdout = subprocess .PIPE ,
415
- stderr = subprocess .PIPE , env = env , preexec_fn = os .setsid )
414
+ with open (input_file_path , "r" ) as input_file , open (output_file_path , "w" ) as output_file , \
415
+ open (result_file_path , "w" ) as result_file :
416
+ process = subprocess .Popen (command , shell = True , stdin = input_file , stdout = output_file ,
417
+ stderr = result_file , env = env , preexec_fn = os .setsid )
416
418
417
419
def sigint_handler (signum , frame ):
418
420
try :
@@ -423,7 +425,7 @@ def sigint_handler(signum, frame):
423
425
signal .signal (signal .SIGINT , sigint_handler )
424
426
425
427
try :
426
- output , lines = process .communicate (timeout = hard_time_limit )
428
+ process .wait (timeout = time_limit )
427
429
except subprocess .TimeoutExpired :
428
430
timeout = True
429
431
try :
@@ -432,11 +434,15 @@ def sigint_handler(signum, frame):
432
434
pass
433
435
process .communicate ()
434
436
437
+ with open (result_file_path , "r" ) as result_file :
438
+ lines = result_file .read ()
439
+ with open (output_file_path , "r" ) as output_file :
440
+ output = output_file .read ()
435
441
result = ExecutionResult ()
436
442
437
443
if not timeout :
438
- lines = lines .decode ( 'utf-8' ). splitlines ()
439
- output = output .decode ( 'utf-8' ). splitlines ()
444
+ lines = lines .splitlines ()
445
+ output = output .splitlines ()
440
446
441
447
for line in lines :
442
448
line = line .strip ()
@@ -476,14 +482,20 @@ def sigint_handler(signum, frame):
476
482
return result
477
483
478
484
479
- def execute_time (self , command , name , result_file_path , input_file_path , output_file_path , answer_file_path ,
485
+ def execute_time (self , name , executable , result_file_path , input_file_path , output_file_path , answer_file_path ,
480
486
time_limit , memory_limit , hard_time_limit ):
481
-
482
- executable = package_util .get_executable (name )
487
+ if sys .platform == 'darwin' :
488
+ time_name = 'gtime'
489
+ elif sys .platform == 'linux' :
490
+ time_name = 'time'
491
+ elif sys .platform == 'win32' or sys .platform == 'cygwin' :
492
+ raise Exception ("Measuring time with GNU time on Windows is not supported." )
493
+
494
+ command = [f'{ time_name } ' , '-f' , '%U\\ n%M\\ n%x' , '-o' , result_file_path , executable ]
483
495
timeout = False
484
496
mem_limit_exceeded = False
485
- with open (input_file_path , "r" ) as input_file :
486
- process = subprocess .Popen (command , stdin = input_file , stdout = subprocess . PIPE , stderr = subprocess .DEVNULL ,
497
+ with open (input_file_path , "r" ) as input_file , open ( output_file_path , "w" ) as output_file :
498
+ process = subprocess .Popen (command , stdin = input_file , stdout = output_file , stderr = subprocess .DEVNULL ,
487
499
preexec_fn = os .setsid )
488
500
489
501
def sigint_handler (signum , frame ):
@@ -520,12 +532,13 @@ def sigint_handler(signum, frame):
520
532
pass
521
533
timeout = True
522
534
break
523
- output , _ = process .communicate ()
524
535
536
+ with open (output_file_path , "r" ) as output_file :
537
+ output = output_file .read ()
525
538
result = ExecutionResult ()
526
539
program_exit_code = None
527
540
if not timeout :
528
- output = output .decode ( "utf-8" ). splitlines ()
541
+ output = output .splitlines ()
529
542
with open (result_file_path , "r" ) as result_file :
530
543
lines = result_file .readlines ()
531
544
if len (lines ) == 3 :
@@ -589,22 +602,10 @@ def run_solution(self, data_for_execution: ExecutionData):
589
602
hard_time_limit_in_s = math .ceil (2 * time_limit / 1000.0 )
590
603
591
604
if self .timetool_name == 'oiejq' :
592
- command = f'"{ timetool_path } " "{ executable } "'
593
-
594
- return self .execute_oiejq (command , name , result_file , test , output_file , self .get_output_file (test ),
605
+ return self .execute_oiejq (name , timetool_path , executable , result_file , test , output_file , self .get_output_file (test ),
595
606
time_limit , memory_limit , hard_time_limit_in_s )
596
607
elif self .timetool_name == 'time' :
597
- if sys .platform == 'darwin' :
598
- timeout_name = 'gtimeout'
599
- time_name = 'gtime'
600
- elif sys .platform == 'linux' :
601
- timeout_name = 'timeout'
602
- time_name = 'time'
603
- elif sys .platform == 'win32' or sys .platform == 'cygwin' :
604
- raise Exception ("Measuring time with GNU time on Windows is not supported." )
605
-
606
- command = [f'{ time_name } ' , '-f' , '%U\\ n%M\\ n%x' , '-o' , result_file , executable ]
607
- return self .execute_time (command , name , result_file , test , output_file , self .get_output_file (test ),
608
+ return self .execute_time (name , executable , result_file , test , output_file , self .get_output_file (test ),
608
609
time_limit , memory_limit , hard_time_limit_in_s )
609
610
610
611
def run_solutions (self , compiled_commands , names , solutions ):
@@ -1179,11 +1180,11 @@ def run(self, args):
1179
1180
self .check_errors (all_results )
1180
1181
try :
1181
1182
validation_results = self .validate_expected_scores (results )
1182
- except :
1183
+ except Exception :
1183
1184
self .config = util .try_fix_config (self .config )
1184
1185
try :
1185
1186
validation_results = self .validate_expected_scores (results )
1186
- except :
1187
+ except Exception :
1187
1188
util .exit_with_error ("Validating expected scores failed. "
1188
1189
"This probably means that `sinol_expected_scores` is broken. "
1189
1190
"Delete it and run `sinol-make run --apply-suggestions` again." )
0 commit comments